NameSilo

[HELP]Regular expression for Price

Spaceship Spaceship
Watch

Just_Dave

Established Member
Impact
2
Hi. I need someones help please. I'm a complete newb to regular expressions, and can't figure this out.

I need it to be able to tell if a str is a price or not. Examples:

"$23.34" = true
"£23.34" = true
"€23.34" = true
"€23213213" = true
"€23.366" = false
"€23.3" = false
"366" = false
"€.366" = false

This is what I've done, but it doesn't work. It just returns false all the time.

Code:
function isPrice($str){
	return(!preg_match("/^(£|$|€)[0-9](\.[0-9]{2})?/", $str)) ? FALSE : TRUE;
}

5 USD for whoever makes it work, through paypal

post it on this thread please.

Thanks very much in advance.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
PHP:
function isPrice($str){
	return(!preg_match("/^([£|$|€])[0-9]+(\.[0-9]{2})?$/", $str)) ? FALSE : TRUE;
}

This is what you are after. You forgot the $ at the end of the regular expression. You also forgot the + after [0-9] anything over 9.99 would not have matched without the +.
 
0
•••
Perfect. thanks. what's your paypal address? (pm)
 
0
•••
Don't worry about the PP Dave. Glad to help.
 
0
•••
thanks very much. I really appreciate it!
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back