Solved

Excluding characters in regular expression

  • 5 April 2022
  • 2 replies
  • 411 views

Hello. I need use a Text-short item in NWC form and i need to avoid the user to use nontypical characters (like symbols like &#@ or accented letters like řžŘÝ). So i want to use Input validation atribut with Regular expression, but i have no clue how the pattern should look like. How to exclude those chars and force to use only latin alphabet lowercase/upercase and numbers? 

icon

Best answer by bsikes 5 April 2022, 23:24

View original

2 replies

Userlevel 4
Badge +10

It may be easiest to specify what characters are acceptable instead of which are not. Not sure on the Latin alphabet part, but this works for the English alphabet:


^([a-z]|[A-Z]|[0-9])*$


 


^ = beginning of string


() = group (an "or" group in this case, separated by | characters)


[] = range of specified characters ([ac] would mean a or c, while [a-c] would mean a, b, or c)


* = match 0 or more characters of what was just specified (in this case, groups of acceptable characters)


$ = End of string


 


Put all together, it's verifying that between the start and end of the string, the only characters present are lowercase a-z, uppercase A-Z, or number 0-9. 

Thanks, it helped and works!

Reply