Regular Expression for comma period dash etc

  • Thread starter Thread starter Sue
  • Start date Start date
S

Sue

Hello

I'm new to this Regular Expression and need some help. I want to
restrict what the user types in a text box.

The User can type only A-Z, a-z, 0-9, spaces, comma, dash, period,
single and double quotes.

If it has anything other than that, I need to display message. How
would I do that? Any help is appreciated.

Thanks
Sue..
 
^[A-Za-z0-9\s,.-]*$

^ (anchor to start of string)
Any character in "A-Za-z0-9\s,.-"
* (zero or more times)
$ (anchor to end of string)

Note the inside the [] the period does not need to be escaped, as it's "any
character" meaning would be pointless there. And the dash does not need to
be escaped because it is last (althought, through the odd alignment of the
ASCII characters, comma-dash-period means exactly the same as
comma-period-dash.)
--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
 
Back
Top