-2

I need to detect following format when I enter serial number like

CK123456.789

I used Regex with pattern of

^(CV[0-9]{6}\.[0-9]{3}

to match but if I enter

CK123456.7890 

it still able to proceed without flagging error. Is there a better regular expression to detect the trailing 3 digits after '.'?

1 Answers1

0

Depending on how you use the regular expression matcher, you might need to enclose it in ^...$ which forces the pattern to be the whole string, i.e.

^CK[0-9]{6}\.[0-9]{3}$ (Note the CK prefix).

I've also removed your leading (mismatched) parenthesis.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483