Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error with a valid regexp #443

Open
12rita opened this issue Nov 19, 2021 · 1 comment
Open

An error with a valid regexp #443

12rita opened this issue Nov 19, 2021 · 1 comment

Comments

@12rita
Copy link

12rita commented Nov 19, 2021

Hi, i'm trying to validate an ip adress, and i'm using a regexp type of rule. But i get an error:
Uncaught SyntaxError: Invalid regular expression: /^(25[0-5/: Unterminated character class.
I opened the function that throws an error, copied it and tried to check my regexp by myself and it worked fine, no errors.
My regular expression:
regex:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\/(\\d){1,2})?$/

I've tried to check within this function:
`regex: function (val, req) {
let reqPattern = req;
var mod = /[g|i|m]{1,3}$/;
var flag = req.match(mod);
flag = flag ? flag[0] : "";

req = req.replace(mod, "").slice(1, -1);
req = new RegExp(req, flag);
return !!req.test(val);

},`

I am willing to figure out, what is going wrong here

I'm using 3.22.1 version of validator js

@RafidMuhymin
Copy link

RafidMuhymin commented Jan 21, 2023

@12rita I think it's happening because your regex contains the | character. Try using array format instead of string format as shown in this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants