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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -