I need javascript regular expression to check string starting with U or C. Also it should be of length 10.
I tried this ^U|C{9}$
but not getting proper results.
I need javascript regular expression to check string starting with U or C. Also it should be of length 10.
I tried this ^U|C{9}$
but not getting proper results.
You should group the tokens when using |
operator, so as to get intended results. Also, you must use .
(any character except new-line) and make sure it is 9 characters long.
You can also use character class as in /^[UC].{9}$/
/^(U|C).{9}$/
You can also use simple javascript to do this
var chr = str.charAt(0);
if((chr == "U" || chr == "C") && str.length == 10){
// valid
}
Use this regex instead:
^[UC].{9}$
The .
will match any character, which you missed out.