ok, i confess, regex is my achillies heel! ive been getting better at it but ive become a bit unstuck in my aim to validate certain fields in some form data.
basically i was trying to verify a price field, only allowing the format:
optional £
one or more digits
"."
2 digits
e.g. £1.00, 1.00 ok
1.0 not ok
i got as far as verifying the x.xx part of the string but im not entirely happy with the code as 1.11111 matches because 1.11 appears in the string as a substirng.
also, another simliar field i have needs to accept numeric values in this form:
25 or 25.0 or 25.00
any help would be much appreciated.
thanks
regex problem
Moderator: General Moderators
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Code: Select all
$pattern = "/^(£)?(\d*)(\.(\d\d))?$/";Code: Select all
$pattern = "/^(\d*)(\.(\d){1,2})?$/";Cheers,
Kieran