ng2-validation-manager icon indicating copy to clipboard operation
ng2-validation-manager copied to clipboard

URL Validation

Open mengi23 opened this issue 6 years ago • 3 comments

I am trying to get a custom URL pattern to work: 'url' : 'required|pattern: [^((http|ftp|https):\/\/)?([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?$]',

BUT I keep getting this "invalid expression" error. Will this pattern not work with your validation manager?

mengi23 avatar Jul 23 '19 15:07 mengi23

@mengi23 your expression has extra ')' Screenshot 2019-07-23 at 17 55 52 and instead of it, use this one [^((http|ftp|https):\/\/)?([\w_-]+(?:(?:\.[\w_-]+)+)([\w.,@?^=%&:\/+#-]*[\w@?^=%&\/+#-])?$]

sabrio avatar Jul 23 '19 15:07 sabrio

Humm... I don't think my expression was wrong. But I replaced with yours it still doesn't like that first char? AddResourceComponent_Host.ngfactory.js? [sm]:1 ERROR SyntaxError: Invalid regular expression: /^ [^((http$/: Unterminated character class at new RegExp () at Function.push../node_modules/@angular/forms/fesm5/forms.js.Validators.pattern (forms.js:596) at validation-manager.js:207 at Array.forEach () at ValidationManager.push../node_modules/ng2-validation-manager/lib/validation-manager.js.ValidationManager.buildControl (validation-manager.js:193) at new ValidationManager (validation-manager.js:18) at AddResourceComponent.push../src/app/pages/resources/add-resource.component.ts.AddResourceComponent.ngOnInit (add-resource.component.ts:127) at checkAndUpdateDirectiveInline (core.js:22099) at checkAndUpdateNodeInline (core.js:23363) at checkAndUpdateNode (core.js:23325)

mengi23 avatar Jul 23 '19 17:07 mengi23

Looks like a bug, unfortunately I am not able to test it, can you try pattern without this character: | and let me know if you are still seeing the same problem or no. Thanks

sabrio avatar Jul 23 '19 20:07 sabrio