0

I am using the following regex pattern with jquery.validate.js and jquery.validate.unobtrusive.js

I put the regex expression into the data-val-regex-pattern attribute of the input element

\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b

this works for 127.0.0.1 but doesn't work for 192.168.2.91

I realize I could add a custom rule, but need to use the data-attribute with the built-in regex rule.

3
  • 1
    Could you create a fiddle for that, because the regex pattern matches both IPs (regexr.com/3cec7).
    – Capricorn
    Commented Dec 17, 2015 at 16:22
  • 1
    Doesn't (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[.](25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[.](25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[.](25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) work? Commented Dec 17, 2015 at 21:57
  • I think the regex will work, I think something is wrong with the special characters. for instance the \\. Commented Dec 18, 2015 at 9:12

1 Answer 1

1

It turns out that $.ajax was appending the Razor generated HTML into the dom and was adding extra \ character so \b was turning into \\b

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.