javascript - I need to let the user input any numbers and characters and only the '-' or the '\' in a field. How do I do that with regular expression? -
A user can enter a serial number with a number or character and only the following special characters: '-' ' '. This is in my code:
if (/ [- \\ a-zA-Z0- 9] /i.test(serialNumber)) {$ ('# serialErrorMsg') .html ( & Lt; div & gt; Invalid format. & Lt; br & gt; beat serial number & lt; br & gt; column name to see valid format; ;); When I put it in a Regedx editor and used the following serial; P23edf-A returns my warning message as a test case in the form of an invalid format.
Maybe it's too late (in the evening and I'm tired), but do you mean If not you do not?
if (! / [- \\ a-zA-Z0- 9] + / I.test (serialNumber) {{code> and a full string To test,
^ [- \\ a-zA-Z0-9] + $
Comments
Post a Comment