i have a textbox in my asp page that i need to validate to allow user to input only text characters from A-Z , a-z... but with spaces allowed between words..
i have tried the following but it doesn't work(doesn't allow spaces)::
^[a-zA-Z]*$
can i change it to make it allow spaces???
Trimming Whitespace You can easily trim unnecessary whitespace from the start and the end of a string or the lines in a text file by doing a regex search-and-replace. Search for ^[ \t]+ and replace with nothing to delete leading whitespace (spaces and tabs). Search for [ \t]+$ to trim trailing whitespace.
Yes, also your regex will match if there are just spaces.
\s stands for “whitespace character”. Again, which characters this actually includes, depends on the regex flavor. In all flavors discussed in this tutorial, it includes [ \t\r\n\f]. That is: \s matches a space, a tab, a carriage return, a line feed, or a form feed.
var nospecial=/^[^* | \ " : < > [ ] { } ` \ ( ) '' ; @ & $]+$/; if(address. match(nospecial)){ alert('Special characters like * | \ " : < > [ ] { } ` \ ( ) \'\' ; @ & $ are not allowed'); return false; but it is not working.
Try this, for regular expression
^[a-zA-Z ]*$
You can add the RegEx character \s to your regular expression, allowing spaces, whitespace and line breaks:
^[a-zA-Z\s]*$
Or, like the other posters said, use a space, to only allow spaces:
^[a-zA-Z ]*$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With