Hi all,

I somehow just couldn't get my regular expression syntax correct. Will you please help 

some examples of my valid string is:

the definition is:
1st 4 characters   - can only be "sinx" or "hkgx" or "bkkx" or "jktx"
next 4 characters - numbers 0 to 9
next 1 character   - a dash "-"
next 3 characters - numbers 0 to 9
next 1 character   - a dash "-"
last 2 characters  - numbers 0 to 9

my problem is how can i make sure the first 4 characters are either "sinx" or "hkgx" 
or "bkkx" or "jktx"?
I've tried:

eregi("[(sinx)|(hkgx)|(bkkx)|(jktx)][0-9]{4}\-[0-9]{3}\-[0-9]{2}$", $string)

but this condition returns a TRUE if the 4th character in the string is "x"!
that means, if my $string = "xxxx0408-001-54", this condition returns me with TRUE!

i also tried the following but they didn't give me the correct results:

eregi("^[(sinx)|(hkgx)|(bkkx)|(jktx)]{4}[0-9]{4}\-[0-9]{3}\-[0-9]{2}$", $string)

eregi("[(sinx)|(hkgx)|(bkkx)|(jktx)]{4}[0-9]{4}\-[0-9]{3}\-[0-9]{2}$", $string)

eregi("(sinx)|(hkgx)|(bkkx)|(jktx)[0-9]{4}\-[0-9]{3}\-[0-9]{2}$", $string)

eregi("^(sinx)|(hkgx)|(bkkx)|(jktx)[0-9]{4}\-[0-9]{3}\-[0-9]{2}$", $string)

does anyone have any suggestions?

Thank you!


Reply via email to