JavaScript Regex: Complicated input validation -


I am trying to create a valid part and / or serial number with rage in combination with the rags.

A valid part number is a two alpha, three digit pattern or / [a-z] {2} \ d {3} /

  is I Aa123 or ZZ443 Etc. ...  

A valid serial number is five digit pattern, or / \ d {5} /

  13245 or 31234 and prompt.  

That part is not a problem. I want to validate combinations and categories:

12345, ab123, ab234-ab245, 12346 - 12349 - Final goal In any combination, the and / or series of streams and / or serial numbers note that the spaces after the specifying the series or after the comma are optional Are there. Note that the part numbers are equal on both sides of a border border (i.e. ab 123 - ab 23 9)

I have two days For now, this expression has been wrestling, and nothing has come better than this:

...

My Reggae-Foo is weak .

First of all, [edge] is incorrect. In addition to the letters, it will match a square bracket, backslash, carat, underscore or backtick - all the letters that are between uppercase letters and lowercase letters in the ASCII character set. You should experiment with the [A-Za-z] , or [AZ] case-insensitive option.

A range of numbers or serial numbers to match a single serial, do this:

  / \ d {5} (?: \ S * - \ S * \ d {5})? /  

... and for part numbers:

  / ([AZ] {2}) \ d {3} (?: \ S * - \ s * \ 1 \ d {3})? / I  

You used \ 4 in your regex, but it was wrong. This may be the fourth group which matches the letter in the first part number, but this was the only first capturing group, so you have \ 1 .

By putting together to match the entire series, you have

  / (?: \ B (?: \ D {5} (?: \ S * - \ s * \ d {5}) | ([AZ] {2}) \ d {3} (?? \ s * - \ s * \ 1 \ d {3})) (?:, \ S * )? + / I  

The comma should be optional, but this means that regex incorrectly 1234512345 or 12345ab123 . It's unlikely that when this happens, I've added the word limit ( \ b ) to cover it between two serial / part numbers / ranges and (? ,, \ S *) Should be at least one non-word character? means that only commas and alternate white places may be your [,] * will allow any number of spaces and / or commas, or nothing.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -