I want to validate a string if and only if meets two conditions:
a. String is exactly 7 characters in length
b.The string format is NNNANNA (N represents digit(0-9) and A alphabet(az,AZ).
Currently I am doing this:
if(preg_match('^d{3}\[a-zA-Z]\d{2}\[a-zA-Z]$', $str) and strlen($str)==7)
{
do something
}
But I am getting this error:
Warning: preg_match(): No ending delimiter '^' found in C:\\wamp\\www\\warrant\\yourproducts\\let.php on line 2
What am I missing?
PS I am horrible with reg expressions.
Ahmar
Your regex is wrong. It should be:
'/^\d{3}[a-zA-Z]\d{2}[a-zA-Z]$/'
OR
'/^\d{3}[a-z]\d{2}[a-z]$/i'
'/^\d{3}[a-zA-Z]\d{2}[a-zA-Z]$/'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.