Click to See Complete Forum and Search --> : Simple Regular Expression


rpanning
10-01-2003, 11:15 PM
Hi, I don't know regular expression stuff yet. What would I use to find out if a string has at least one alfa-numeric value entered? I plan on using string.search() Also what would I use to find out if only a positive or negative number was entered? Thanks

Jeff Mott
10-02-2003, 12:50 AM
What would I use to find out if a string has at least one alfa-numeric value entered?string.search(/\w/) != -1; // alphanumeric and underscoreAlso what would I use to find out if only a positive or negative number was entered?Does this mean any number? Or anything but zero?

Charles
10-02-2003, 05:25 AM
I think that you will find the RegExp.test() (http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/regexp.html#1194128) will work just a tiny bit better, in this case, than String.search() (http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/string.html#1194332).