Regular Expression question
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   neal_ravindran
Posted On:   Friday, November 7, 2003 05:09 AM

To prevent users from entering anything other than alphabets, space or a full-stop, I use this reqular expression as

var re=/[^a-zA-Z_0-9s.]/;

Then use if(re.test(inputStr)) and alert if I find illegal chars. But it seems to bypass all what I want to eliminate(like apostrophes, fwd slashes etc). What is wrong with that regular expression above...iow, why is it not doing what I want(I need only alphabets, underscores, periods and spaces in the string..anything else is illegal in my case) Can you spot?

Re: Regular Expression question

Posted By:   The_Dude  
Posted On:   Friday, November 7, 2003 06:19 AM

var re=/[^a-zA-Z_0-9s.]/;



should be:



var re=/^[a-zA-Z_0-9s.].*$/;

the `^' inside of [] negates

About | Sitemap | Contact