Search code examples
regexvalidationunicodestruts-1struts-validation

Blacklist regular expression to validate human name in any language


I am using Struts 1.3.1 validator (validation.xml, using mask and regular expression), which doesn't support Unicode regular expressions. (I read and I tried)

When it's a whitelist, and unicode, it should be something like this:

^[\p{L}\p{P}\p{Zs}]+

Yet, in my case, I need to filter all "helping characters" and leave out letters only.

Does anyone have an idea of a blacklist regular expression to answer my needs?

I though of this one, but it obviously doesn't cover everything:

^[^&^>^/^<^\\^*^\?^%^:]$

Thanks a lot!


Solution

  • This is the solution I chose in the end:

    Note! this is Struts 1.3.1 syntax for a validator mask!

    ^[^&><\\*?%:!"#$()+,;=@\[\]{}~\^|`\n\t\r/]+$
    

    Disallowing special characters, allowing others.

    This was considered as a white-list approach, but was neglected as it needed work (adding other languages other than European and Japanese/Chinese):

    ^[a-zA-Z0-9\-'àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòóÒôÔöÖùúÙûÛüÜçÇ’ñß]+|[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+|[々〆〤]+$