NameSilo

[HELP]Regular expression for Price

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
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
Close
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
Close
Perfect. thanks. what's your paypal address? (pm)
 
0
Close
Don't worry about the PP Dave. Glad to help.
 
0
Close
thanks very much. I really appreciate it!
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back