[HELP]Regular expression for Price

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by 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.
GoDaddyGoDaddy
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
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Parking: a plain list of your portfolio domains
Your public portfolio page has a new option in the menu next to the sort options. "Domain list" opens a plain page with one domain name...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back