availity-reactstrap-validation icon indicating copy to clipboard operation
availity-reactstrap-validation copied to clipboard

regex with options arguments attached fails silently, causing onInvalidSubmit to fire

Open r3wt opened this issue 6 years ago • 4 comments

<AvField label='Add Link' validate={{
  pattern:{ value: /(^|\s)((https?:\/\/)[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi, errorMessage:'Invalid URL entered' },
  maxLength:{ value: 2048, errorMessage:'URL\'s longer than 2048 characters are not accepted' },
  required: { value: true, errorMessage:'Enter a URL' }
}} />

if omit the gi modifier to the regex, the field works correctly.

r3wt avatar Nov 25 '19 22:11 r3wt

Can you try using new RegExp? We are using lodash's isRegExp to determine if a regex is provided directly.

TheSharpieOne avatar Nov 25 '19 22:11 TheSharpieOne

Can you try using new RegExp? We are using lodash's isRegExp to determine if a regex is provided directly.

why complicate things with useless library functions, when native javascript can tell you what something is using the instanceof operator? /a/gi instanceof RegExp // true

r3wt avatar Nov 25 '19 23:11 r3wt

_.isRegExp(/(^|\s)((https?:\/\/)[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi); // true as well, which is why this is interesting.

TheSharpieOne avatar Nov 25 '19 23:11 TheSharpieOne

Hmm, that is truly strange. were you able to reproduce? if not, then i wonder if it could have been something off with babel or webpack. i've noticed quite a few side effects/bugs related to the latest webpack/babel this project is based on.

webpack version : 4.41.0 babel core version: 7.6.0

r3wt avatar Nov 25 '19 23:11 r3wt