I recently made some changes to code and was made aware that one of the pages that was updated does not work on the iPhone browser. Sure enough, it didn't, but worked in all other browsers I tested.
Can anyone see something or give some insight as to why this particular line of code would fail on an iphone browser, but works elsewhere? There is something about the regex that iPhone does not like and I need to make it compatible. Note that the browser errors on this line not that the regex itself is failing if that makes sense.
I don't know of a way to see the debug info on an iphone browser to see if any information is provided. I do know that if I remove the regex pattern from below the page works again on iPhone which tells me that is the problem.
return this.optional(element) || /^(\*\.|((?!-)[a-z0-9-]{1,255}(?<!-)\.))((?!-)[a-z0-9-]{1,255}(?<!-)\.)*[a-z]{2,}$/i.test(value);
CodePudding user response:
Safari on iOS does not support lookbehind (at the time of writing). Your regex uses lookbehind here: (?<!-)
You can avoid that lookbehind by replacing this part:
[a-z0-9-]{1,255}(?<!-)
with this:
[a-z0-9-]{0,254}[a-z0-9]