Need Regular Expression for 30 character limit with no spaces or special characters

chrish5
Giga Guru

Hi Community,

I am currently using a regular expression of .{1,30} to limit the characters to 30 on a field.  I want to add to it so no spaces (beginning, middle or end) are allowed and no special characters are allowed.  Can anybody help with this?   Thanks!

1 ACCEPTED SOLUTION

Hi @chrish5,

 

This should be better 🙂 

 

^([A-z]|[0-9]){1,30}$


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

13 REPLIES 13

Peter Bodelier
Giga Sage

Hi @chrish5,

 

Try ([A-z]|[0-9]){1,30}


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi Peter.  Thanks for your reply.  I tried that but it still allows spaces at the begging and end of the string.  I would like to prohibit spaces anywhere in this 30 character max string.  Any idea on how to accomplish that? 

Hi @chrish5,

 

This should be better 🙂 

 

^([A-z]|[0-9]){1,30}$


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi Peter, 

When I test this it catches the spaces in the middle, but unfortunately it is still allowing spaces at the beginning and the end of the string.  

 

Thanks,

Chris