Hi,
I want to test a sting to see if its valid.
It must be JUST "e" OR numbers. Would this work:
if(!eregi("^(e){1,1}$", $string) || !eregi("^[0-9]+", $string) { print "No, your totally wrong!" }
Thank you! 😃
I think that'd work, except for a small detail. Why did you add the '$' at the end of the first one but not the other one? If you don't add it to the second one, then "1aaa" will be match your regular expression...
Diego
The first one was because I want to check for only ONE "e" the second, I need to check for number(s), if I put a $ at the end, that would mean it would only allow 1 character... The second one wouldn't match 1aaaa, it says only 0-9, right? 😕
The regular expression for just 'e' or numbers is this:
^(e|[0-9])+$
See if that does what you want.
How many numbers can there be?
What about
if(!($string=='e' || $string=='E') || !is_numeric($string)) { // totally wrong. }
? It's probably the fastest (especially testing for e/E)
Oh gosh, I never thought of the is_numeric function... 😃 Thanks