PDA

View Full Version : building RegExp to find this:


frontline
05-18-2003, 10:02 AM
hello
how can i build regexp that will return true if the string format is
"number*" that is : "34334*" is valid, but this: "3333*333" is not valid
and of curse this "333**22*" is not valid also only number that fallows "*" in the end with out space between the number and the "*"
thanks!

scroots
05-18-2003, 10:10 AM
they are quite easy to learn, or atleast pick up what you need from them.

http://www.javascriptkit.com/javatutors/re.shtml

scroots

jalarie
05-22-2003, 04:06 PM
frontline, try something like this:

 a=prompt('?',0);
 if (a.match('^[0-9]+(\*){1}$')) {
  alert('true');
 } else {
  alert('false');
 }

Explaination:

 ^ demands the beginning of the item.
 [0-9]+ requires one or more digits.
 (\*){1} forces exactly one star.
 $ demands that we be at the end.