alpha-numeric fields
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
alpha-numeric fields
Hi,
How can I check whether a field a certain contains letters and numbers? But in particular a certain amount of numbers.
i.e.
Field value = v41u3
How can I check if this field contains only 3 numbers?
Thanks.
How can I check whether a field a certain contains letters and numbers? But in particular a certain amount of numbers.
i.e.
Field value = v41u3
How can I check if this field contains only 3 numbers?
Thanks.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
preg_match_all() returns the number of matches. The pattern to use is only \d, nothing more. It can't get more simple then that.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Well, you have to use a delimiter either side of the regex (I use '~' and so the actual regex would be '~\d~')and use count() on the return value.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
Are you counting _digits_ or _numbers_ in a string? If first, just test the string against
if it matches, the string is alphanumeric and contains 1, 2 or 3 digits (change {1,3} to {3} to require exactly 3).
Code: Select all
$re = '~^[a-z]*([0-9][a-z]*){1,3}$~iD';- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London