10 Replies - 250 Views - Last Post: 11 June 2019 - 01:01 AM

#1 JamesAndersonJr   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 26
  • Joined: 03-December 13

Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 08 June 2019 - 06:18 PM

Why does this RegEx pattern purposed to validate a person's full name always cash upon inputting many characters? :(/>/>


<input type="text" id="my_text_box" maxlength="50" pattern="([^\d\s\W]+){2,}['-\.]{0,1}([^\d\s\W]+)*([ ]{0,1}([^\d\s\W]+){2,}['-\.]{0,1}([^\d\s\W]+)*)*"  title="Please enter your FULL name." style="width:350px;height:auto;" required>

This post has been edited by JamesAndersonJr: 08 June 2019 - 06:19 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15225
  • View blog
  • Posts: 60,941
  • Joined: 12-June 08

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 08 June 2019 - 08:46 PM

What is your test text?

Throwing that in a regex tester I am not certain what the result is supposed to be.
https://regex101.com/

Throwing it into a form, it doesn't crash. Are you certain that's what is causing a browser to crash?

 <form action="">

	<input type="text" id="my_text_box" maxlength="50" pattern="([^\d\s\W]+){2,}['-\.]{0,1}([^\d\s\W]+)*([ ]{0,1}([^\d\s\W]+){2,}['-\.]{0,1}([^\d\s\W]+)*)*"  title="Please enter your FULL name." style="width:350px;height:auto;" required>
<br />
<input type="submit">
</form> 


Was This Post Helpful? 0
  • +
  • -

#3 JamesAndersonJr   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 26
  • Joined: 03-December 13

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 09 June 2019 - 07:53 AM

Honestly, it could be that this oldie of a computer (Mobo: ASUS P8Z77-V LE PLUS with a 'second-hand' possibly previously secretly overclocked Intel Core i7-3700) is the problem, and not my code.

I have a second computer with similar hardware, but all parts were brand new when I brought them. Maybe I can try on that. I'll post back when I do.
Was This Post Helpful? 0
  • +
  • -

#4 JamesAndersonJr   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 26
  • Joined: 03-December 13

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 09 June 2019 - 08:04 AM

BTW, the RegEx is supposed to validate that a text field intended for a persons full name does not include invalid characters like !@#$%^&* or digits, but allows for all possible First and last names, and even titles prefixes and suffixes like: Dr. John Mc'Carthy-Johnson Dö Jr. III

<script>
alert(/([^\d\s\W]+){2,}['-\.]{0,1}([^\d\s\W]+)*([ ]{0,1}([^\d\s\W]+){2,}['-\.]{0,1}([^\d\s\W]+)*)*/.test("Dr. John Mc'Carthy-Johnson Dö Jr. III"));
</script>

This post has been edited by JamesAndersonJr: 09 June 2019 - 08:06 AM

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15225
  • View blog
  • Posts: 60,941
  • Joined: 12-June 08

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 09 June 2019 - 09:14 AM

Honestly it would be.. weird... if a regex string for a random textbox would be doing that. I would be checking for errors in the console and other, larger, things in play.
Was This Post Helpful? 0
  • +
  • -

#6 JamesAndersonJr   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 26
  • Joined: 03-December 13

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 09 June 2019 - 12:54 PM

Found the problem, and improved my RegEx in the meantime. I was missing the ^ symbol at the beginning of my RegEx, and it was wreaking havoc on the browser.

Here is the new and improved code:


<input type="text" name="full_name" id="full_name" maxlength="50" pattern="^(([^\d\s\W_]|[\u00C0-\u00FF])+){2,}(['’,\-\.]+)?(([^\d\s\W_]|[\u00C0-\u00FF]))*(([ ]+){0,1}((([^\d\s\W_]|[\u00C0-\u00FF])+){2,})(['’\-,\.]+)?((([^\d\s\W_]|[\u00C0-\u00FF])){2,})?)*$" title="Please enter your FULL name." style="width:250px;height:auto;" required>

This post has been edited by JamesAndersonJr: 09 June 2019 - 12:56 PM

Was This Post Helpful? 0
  • +
  • -

#7 JamesAndersonJr   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 26
  • Joined: 03-December 13

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 10 June 2019 - 08:57 AM

I finally settled on a whole new RegEx because the problem came back, so here is a demo of the new code-base I'm now using:

<!DOCTYPE html>
<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Test Form Page</title>

<script>

/* 'manage_cookies.min.js' [BEGIN] */

function set_cookie(e,o,t,n,c){var i=e+"="+escape(o),u=new Date,l=u.getTime();l+=21e5,u.setTime(l),i+="; expires="+u.toGMTString(),t&&(i+="; path="+escape(t)),n&&(i+="; domain="+escape(n)),c&&(i+="; secure"),document.cookie=i}function get_cookie(e){var o=document.cookie.match("(^|;)/>/>/> ?"+e+"=([^;]*)(;|$)");return o?unescape(o[2]):null}function doesCookieExist(e){return!!get_cookie(e)}function deleteAllCookies(){for(var e=document.cookie.split(";"),o=0;o<e.length;o++){var t=e[o],n=t.indexOf("="),c=-1<n?t.substr(0,n):t;document.cookie=c+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT"}}function iCheckSetCookieValFill(e,o){get_cookie(e)?document.getElementById(e).value=get_cookie(e):(set_cookie(e,o),document.getElementById(e).value=o)}function nCheckSetCookieValFill(e,o){get_cookie(e)?document.getElementsByName(e)[0].value=get_cookie(e):(set_cookie(e,o),document.getElementsByName(e)[0].value=o)}function nCheckCookieValFill(e){get_cookie(e)&&(document.getElementsByName(e)[0].value=get_cookie(e))}function updateElementAndCookie(e,o){set_cookie(e,o),document.getElementById(e).value=o}

/* 'manage_cookies.min.js' [END] */

/* 'dynamic_format.min.js' [BEGIN] */

if(String.prototype.trimLeft=function(e){return void 0===e&&(e="s"),this.replace(new RegExp("^["+e+"]+"),"")},String.prototype.trimRight=function(e){return void 0===e&&(e="s"),this.replace(new RegExp("["+e+"]+$"),"")},String.prototype.trim=function(e){return this.trimLeft(e).trimRight(e)},Number.isNaN||(Number.isNaN=function(e){return e!=e}),Number.isInteger||(Number.isInteger=function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e}),Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),Array.prototype.forEach||(Array.prototype.forEach=function(e){var t,n;if(null==this)throw new TypeError("this is null or not defined");var a=Object(this),r=a.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(1<arguments.length&&(t=arguments[1]),n=0;n<r;){var o;n in a&&(o=a[n],e.call(t,o,n,a)),n++}}),String.prototype.includes||(String.prototype.includes=function(e,t){"use strict";return"number"!=typeof t&&(t=0),!(t+e.length>this.length)&&-1!==this.indexOf(e,t)}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/gm,"")}),String.prototype.padStart||(String.prototype.padStart=function(e,t){return e>>=0,t=String(void 0!==t?t:" "),this.length>=e?String(this):(/>/>/>(e-=this.length)>t.length&&(t+=t.repeat(e/t.length)),t.slice(0,e)+String(this))}),"function"!=typeof getWholeChar)function getWholeChar(e,t){var n=e.charCodeAt(t);if(Number.isNaN(n))return"";if(n<55296||57343<n)return e.charAt(t);if(55296<=n&&n<=56319){if(e.length<=t+1)throw"High surrogate without following low surrogate";var a=e.charCodeAt(t+1);if(a<56320||57343<a)throw"High surrogate without following low surrogate";return e.charAt(t)+e.charAt(t+1)}if(0===t)throw"Low surrogate without preceding high surrogate";var r=e.charCodeAt(t-1);if(r<55296||56319<r)throw"Low surrogate without preceding high surrogate";return!1}if("function"!=typeof canHaveValueAttrib)function canHaveValueAttrib(e){if(!document.getElementById(e))return!1;var t=document.getElementById(e);switch(String(t.tagName).toLowerCase()){case"button":case"data":case"input":case"meter":case"li":case"option":case"progress":case"param":case"textarea":return!0;default:return!1}}if("function"!=typeof isAllElmtTextSelected)function isAllElmtTextSelected(e){if(document.getElementById(e)){var t=document.getElementById(e);return"number"==(typeof t.selectionstart).toLowerCase()?0==t.selectionstart&&t.selectionend==t.value.length&&t.selectionstart!=t.value.length:"undefined"!=(typeof document.selection).toLowerCase()&&(t.focus(),document.selection.createRange().text==t.value&&0<t.value.length)}}if("function"!=typeof setInputFilter)function setInputFilter(e,t,n){if(document.getElementById(e)){var a=document.getElementById(e),r=new RegExp(t),o=[];n||(n=["input","keydown","keyup","mousedown","mouseup","select","contextmenu","drop"]),Array.isArray(n)||(console.error("Error: Argument ['evt_arr'] passed to function 'setInputFilter(..)', in file 'dynamic_format.min.js' is not an array."),o.push(n),n=o),inputFilter=function(e){return r.test(e)},n.forEach(function(e){a.addEventListener(e,function(){inputFilter(this.value)?(this.oldValue=this.value,this.oldSelectionstart=this.selectionstart,this.oldSelectionend=this.selectionend):this.hasOwnProperty("oldValue")&&(this.value=this.oldValue,this.setSelectionRange(this.oldSelectionstart,this.oldSelectionend))})})}}if("function"!=typeof getInputSelection)function getInputSelection(e){var t=document.getElementById(e);t.focus();var n,a,r,o,l,i=0,s=0;return"number"==(typeof t.selectionstart).toLowerCase()&&"number"==(typeof t.selectionend).toLowerCase()?(i=t.selectionstart,s=t.selectionend):(a=document.selection.createRange())&&a.parentElement()==t&&(o=t.value.length,n=t.value.replace(/\r\n/g,"\n"),(r=t.createTextRange()).moveToBookmark(a.getBookmark()),(l=t.createTextRange()).collapse(!1),-1<r.compareEndPoints("StartToEnd",l)?i=s=o:(i=-r.moveStart("character",-o),i+=n.slice(0,i).split("\n").length-1,-1<r.compareEndPoints("EndToEnd",l)?s=o:(s=-r.moveEnd("character",-o),s+=n.slice(0,s).split("\n").length-1))),{start:i,end:s}}function convertStrToBool(e){switch(String(e).toLowerCase()){case"true":case"yes":case"t":case"y":case"1":case"on":return!0;case"false":case"no":case"f":case"n":case"0":case"off":case"":default:return!1}}function convertStrToBoolean(e){return convertStrToBool(e)}function putElmtSelectedRangeIntoData(e){if(document.getElementById(e)&&"function"==typeof getInputSelection){var t=getInputSelection(e);sessionStorage.setItem(e+"_data-sel-start",t.start),sessionStorage.setItem(e+"_data-sel-end",t.end)}}function setElmtSelectedRangeFromData(e){if(document.getElementById(e)){var t=document.getElementById(e);isNaN(Math.abs(parseInt(sessionStorage.getItem(e+"_data-sel-start"))))||isNaN(Math.abs(parseInt(sessionStorage.getItem(e+"_data-sel-end"))))||t.setSelectionRange(Math.abs(parseInt(sessionStorage.getItem(e+"_data-sel-start"))),Math.abs(parseInt(sessionStorage.getItem(e+"_data-sel-end"))))}return!0}function strToUCWords(e){var t,n;for(t=(e=(e=String(e)).replace(/((\r?\n)|(\n?\r))/gm,"\n")).split(/\u000A/),n=0;n<t.length;n++)t[n]=getWholeChar(t[n],0).toUpperCase()+String(t[n].substring(1));for(t=(e=t.join("\n")).split(/[^\S\r\n]/gm),n=0;n<t.length;n++)t[n]=getWholeChar(t[n],0).toUpperCase()+String(t[n].substring(1));return e=t.join(" ")}function strToUCWordsStrict(e){var t,n;for(t=(e=(e=String(e)).replace(/((\r?\n)|(\n?\r))/gm,"\n")).split(/\u000A/),n=0;n<t.length;n++)t[n]=getWholeChar(t[n],0).toUpperCase()+String(t[n].substring(1)).toLowerCase();for(t=(e=t.join("\n")).split(/[^\S\r\n]/gm),n=0;n<t.length;n++)t[n]=getWholeChar(t[n],0).toUpperCase()+String(t[n].substring(1)).toLowerCase();return e=t.join(" ")}function strToTitleCase(e){return strToUCWords(e)}function toTitleCase(e){return strToUCWords(e)}function toTitleCaseLax(e){return strToUCWords(e)}function toTitleCaseStrict(e){return strToUCWordsStrict(e)}function formatNumToLocal(e,t){if("function"==typeof Number.toLocaleString)return t||(t="en"),isNaN(e)?"NaN":Number(e).toLocaleString(t)}function autoFormatIntCurrency(e,t,n){if("function"==typeof Intl.NumberFormat&&(isNaN(e)&&(e=0),!isNaN(e)))return t&&3===parseInt(String(t).length)||(t="USD"),n||(n="en"),new Intl.NumberFormat(n,{style:"currency",currency:t}).format(e)}function delAllInstancesOfACharInAStr(e,t){t="\\"+String(t);var n=new RegExp(t,"gm");return String(e).replace(n,"")}function delAllInstancesOfACharInAnElmt(e,t){return document.getElementById(e)&&(putElmtSelectedRangeIntoData(e),elmt=document.getElementById(e),canHaveValueAttrib(e)?elmt.value=delAllInstancesOfACharInAStr(elmt.value,t):elmt.innerHTML=delAllInstancesOfACharInAStr(elmt.innerHTML,t),setElmtSelectedRangeFromData(e)),!0}function delLastChar(e){if(document.getElementById(e)){putElmtSelectedRangeIntoData(e);var t=document.getElementById(e).value.length;document.getElementById(e).value=String(document.getElementById(e).value).slice(0,t-1),setElmtSelectedRangeFromData(e)}}function delEndChar(e){delLastChar(e)}function delFirstChar(e){document.getElementById(e)&&(putElmtSelectedRangeIntoData(e),document.getElementById(e).value=String(document.getElementById(e).value).slice(1),setElmtSelectedRangeFromData(e))}function trimStrg(e){return(e=String(e)).replace(/^\s+|\s+$/gm,"")}function trimPrecedingSpaces(e){return e.replace(/^\s+/,"")}function trimSucceedingSpaces(e){return e.replace(/\s+$/,"")}function removeAllSpaces(e){return(e=String(e)).replace(/\s/gm,"")}function removeAllExtraSpaces(e){return e=(e=String(e)).replace(/[^\S\r\n]+/gm," ")}function removeAllExtraSpacesAndTrim(e){return e=trimStrg(removeAllExtraSpaces(e=String(e)))}function removeAllPrecedingZeros(e){return(e=String(e)).replace(/^0+/,"")}if("function"!=typeof autoFormatPosDecAmtField)function autoFormatPosDecAmtField(e){if(document.getElementById(e)){var t,n,a,r,o=document.getElementById(e);putElmtSelectedRangeIntoData(e),t=canHaveValueAttrib(e)?o.value:o.innerHTML,o.maxLength&&(n=o.maxLength),(t=String(t).replace(/[^\d\.]/gim,"")).includes(".")&&(a=t.substring(0,t.lastIndexOf(".")),r=t.substring(t.lastIndexOf(".")+1),a=String(a).replace(/[^\d]/gim,""),r=String(r).replace(/[^\d]/gim,""),2<String(r).length&&(r=String(r).substring(0,2)),t=String(a)+"."+String(r)),void 0!==n&&n&&Number.isInteger(parseInt(n))&&0<parseInt(n)&&(t=t.substring(0,parseInt(n))),canHaveValueAttrib(e)?o.value=t:o.innerHTML=t,setElmtSelectedRangeFromData(e)}}if("function"!=typeof autoFormatPosDecAmtFieldonpaste)function autoFormatPosDecAmtFieldonpaste(e){if(document.getElementById(e)){var t,n=document.getElementById(e);n.maxLength&&(t=n.maxLength),n.onpaste=function(){n.removeAttribute("maxLength"),setTimeout(function(){autoFormatPosDecAmtField(e),putElmtSelectedRangeIntoData(e),void 0!==t&&t&&Number.isInteger(parseInt(t))&&0<parseInt(t)&&n.setAttribute("maxLength",parseInt(t)),setElmtSelectedRangeFromData(e)},10)}}}if("function"!=typeof autoFormatPosIntField)function autoFormatPosIntField(e){if(document.getElementById(e)){var t,n,a=document.getElementById(e);putElmtSelectedRangeIntoData(e),t=canHaveValueAttrib(e)?a.value:a.innerHTML,a.maxLength&&(n=a.maxLength),t=String(t).replace(/[\D]/gim,""),void 0!==n&&n&&Number.isInteger(parseInt(n))&&0<parseInt(n)&&(t=t.substring(0,parseInt(n))),canHaveValueAttrib(e)?a.value=t:a.innerHTML=t,setElmtSelectedRangeFromData(e)}}if("function"!=typeof autoFormatPosIntFieldonpaste)function autoFormatPosIntFieldonpaste(e){if(document.getElementById(e)){var t,n=document.getElementById(e);n.maxLength&&(t=n.maxLength),n.onpaste=function(){n.removeAttribute("maxLength"),setTimeout(function(){autoFormatPosIntField(e),putElmtSelectedRangeIntoData(e),void 0!==t&&t&&Number.isInteger(parseInt(t))&&0<parseInt(t)&&n.setAttribute("maxLength",parseInt(t)),setElmtSelectedRangeFromData(e)},10)}}}function autoFormatNameField(e){if(document.getElementById(e)){var t,n,a=document.getElementById(e);putElmtSelectedRangeIntoData(e),t=canHaveValueAttrib(e)?a.value:a.innerHTML,a.maxLength&&(n=a.maxLength),t=strToUCWords(t=(t=trimPrecedingSpaces(removeAllExtraSpaces(String(t)))).replace(/([^a-zA-Z\u00C0-\u017F\u1E02-\u1EF3\u000A\s\.'`’,\-~&]|[\u00D7\u00F7])/gim,"")),void 0!==n&&n&&Number.isInteger(parseInt(n))&&0<parseInt(n)&&(t=t.substring(0,parseInt(n))),canHaveValueAttrib(e)?a.value=t:a.innerHTML=t,setElmtSelectedRangeFromData(e)}}function autoFormatNameFieldonpaste(e){if(document.getElementById(e)){var t,n=document.getElementById(e);n.maxLength&&(t=n.maxLength),n.onpaste=function(){n.removeAttribute("maxLength"),setTimeout(function(){autoFormatNameField(e),putElmtSelectedRangeIntoData(e),n.value=trimSucceedingSpaces(n.value),void 0!==t&&t&&Number.isInteger(parseInt(t))&&0<parseInt(t)&&n.setAttribute("maxLength",parseInt(t)),setElmtSelectedRangeFromData(e)},10)}}}function autoFormatEmailField(e){if(document.getElementById(e)){var t,n,a,r,o,l,i=document.getElementById(e);putElmtSelectedRangeIntoData(e),t=canHaveValueAttrib(e)?i.value:i.innerHTML,i.maxLength&&(l=i.maxLength),t=trimPrecedingSpaces(removeAllExtraSpaces(String(t))),o=/(('|")$)/gm,t=(r=/(^('|"))/gm).test(t)||o.test(t)?t.replace(/[^a-zA-Z\d\u00C0-\u017F\.!#$%&@'"\*\+\-\/=\?\^_`\{\|\}~\(\)\u0020\t,\:;<>\[\\\]]/gim,""):t.replace(/[^a-zA-Z\d\u00C0-\u017F\.!#$%&@'"\*\+\-\/=\?\^_`\{\|\}~\(\)]/gim,""),r.test(t)||(t=t.replace(/(^\.+)/gm,"")),t.includes("@")&&(n=t.substring(0,t.lastIndexOf("@")),a=t.substring(t.lastIndexOf("@")+1),t=(n=/((^(').*(')$)|(^(").*(")$))/gm.test(n)?n.replace(/[^a-zA-Z\d\u00C0-\u017F\.!#$%&@'"\*\+\-\/=\?\^_`\{\|\}~\(\)\u0020\t,\:;<>\[\\\]]/gim,""):(n=(n=(n=n.replace(/[^a-zA-Z\d\u00C0-\u017F\.!#$%&@'"\*\+\-\/=\?\^_`\{\|\}~\(\)]/gim,"")).replace(/\.{2,}/gm,".")).replace(/(^\.+|\.+$)/gm,"")).replace(/(^\s+|\s+$)/gm,""))+"@"+(a=(a=a.replace(/[^a-zA-Z\d\.\-]/gm,"")).replace(/((^\-+)|(\-+$))/gm,""))),void 0!==l&&l&&Number.isInteger(parseInt(l))&&0<parseInt(l)&&(t=t.substring(0,parseInt(l))),canHaveValueAttrib(e)?i.value=t:i.innerHTML=t,setElmtSelectedRangeFromData(e)}}function autoFormatEmailFieldonpaste(e){if(document.getElementById(e)){var t,n=document.getElementById(e);n.maxLength&&(t=n.maxLength),n.onpaste=function(){n.removeAttribute("maxLength"),setTimeout(function(){autoFormatEmailField(e),putElmtSelectedRangeIntoData(e),n.value=trimSucceedingSpaces(n.value),void 0!==t&&t&&Number.isInteger(parseInt(t))&&0<parseInt(t)&&n.setAttribute("maxLength",parseInt(t)),setElmtSelectedRangeFromData(e)},10)}}}function autoFormatUSPhoneNumField(e){if(document.getElementById(e)){var t,n,a,r=document.getElementById(e);if(canHaveValueAttrib(e)?elmt_val=r.value:elmt_val=r.innerHTML,elmt_val=String(elmt_val).replace(/[^\d]/gm,""),t=parseInt(String(elmt_val).length),1==elmt_val.charAt(0))switch(n=11,a=parseInt(t)<parseInt(n)?parseInt(t):parseInt(n),elmt_val=elmt_val.substring(0,a),t=parseInt(elmt_val.length)){case 11:case 10:case 9:case 8:elmt_val=elmt_val.slice(0,1)+" ("+elmt_val.slice(1,4)+") "+elmt_val.slice(4,7)+"-"+elmt_val.slice(7,t);break;case 7:elmt_val=elmt_val.slice(0,1)+" ("+elmt_val.slice(1,4)+") "+elmt_val.slice(4,7);break;case 6:case 5:elmt_val=elmt_val.slice(0,1)+" ("+elmt_val.slice(1,4)+") "+elmt_val.slice(4,t);break;case 4:elmt_val=elmt_val.slice(0,1)+" ("+elmt_val.slice(1,4);break;case 3:case 2:elmt_val=elmt_val.slice(0,1)+" ("+elmt_val.slice(1,t);break;case 1:elmt_val=elmt_val.slice(0,1)}else switch(n=10,a=parseInt(t)<parseInt(n)?parseInt(t):parseInt(n),elmt_val=elmt_val.substring(0,a),t=parseInt(elmt_val.length)){case 10:case 9:case 8:case 7:elmt_val="("+elmt_val.slice(0,3)+") "+elmt_val.slice(3,6)+"-"+elmt_val.slice(6,t);break;case 6:elmt_val="("+elmt_val.slice(0,3)+") "+elmt_val.slice(3,6);break;case 5:case 4:elmt_val="("+elmt_val.slice(0,3)+") "+elmt_val.slice(3,t);break;case 3:elmt_val="("+elmt_val.slice(0,3);break;case 2:case 1:elmt_val="("+elmt_val.slice(0,t)}canHaveValueAttrib(e)?r.value=elmt_val:r.innerHTML=elmt_val}}function autoFormatUSPhoneNumFieldonpaste(e){if(document.getElementById(e)){var t=document.getElementById(e);if(t.maxLength)var n=t.maxLength;t.onpaste=function(){t.removeAttribute("maxLength"),setTimeout(function(){autoFormatUSPhoneNumField(e),putElmtSelectedRangeIntoData(e),void 0!==n&&n&&Number.isInteger(parseInt(n))&&0<parseInt(n)&&t.setAttribute("maxLength",parseInt(n)),setElmtSelectedRangeFromData(e)},10)}}}function formatNumericValue(e,t,n){if(document.getElementById(e)){putElmtSelectedRangeIntoData(e);var a=document.getElementById(e);for(t||(t=","),n||(n=".");"0"==a.value.charAt(0);)a.value=a.value.substr(1);var r=new RegExp(t,"g");if(out_str=a.value.replace(r,""),!isNaN(out_str)){if(lft_str=out_str,rgt_str="",-1<out_str.indexOf(n)&&(lft_str=out_str.substr(0,out_str.indexOf(n)),rgt_str=out_str.substr(out_str.indexOf(n)+1)),3<lft_str.length){num_dgt_grp_sep_chars=Math.floor((lft_str.length-1)/3),temp_str="";for(var o=0;o<num_dgt_grp_sep_chars;o++)temp_str=t+lft_str.substr(lft_str.length-3)+temp_str,lft_str=lft_str.substr(0,lft_str.length-3);lft_str+=temp_str}out_str=-1<out_str.indexOf(n)?lft_str+n+rgt_str:lft_str,a.value=out_str}setElmtSelectedRangeFromData(e)}return!0}function removeAllSpacesonpaste(e){if(document.getElementById(e)){var t,n,a=document.getElementById(e);a.maxLength&&(n=a.maxLength),a.onpaste=function(){a.removeAttribute("maxLength"),setTimeout(function(){t=a.value,t=removeAllSpaces(String(t)),void 0!==n&&n&&Number.isInteger(parseInt(n))&&0<parseInt(n)&&(t=t.substring(0,parseInt(n)),a.setAttribute("maxLength",parseInt(n))),a.value=t},10)}}}function trimElmtonpaste(e){if(document.getElementById(e)){var t,n,a=document.getElementById(e);a.maxLength&&(n=a.maxLength),document.getElementById(e).onpaste=function(){a.removeAttribute("maxLength"),setTimeout(function(){t=a.value,t=removeAllExtraSpacesAndTrim(String(t)),void 0!==n&&n&&Number.isInteger(parseInt(n))&&0<parseInt(n)&&(t=t.substring(0,parseInt(n)),a.setAttribute("maxLength",parseInt(n))),a.value=t},10)}}}function trimAmtElmt(e,t,n,a,r){if(r&&"string"==typeof r&&1===parseInt(r.length)||(r="."),n&&"string"==typeof n&&1===parseInt(n.length)||(n=","),document.getElementById(e)){putElmtSelectedRangeIntoData(e);var o,l,i,s,u=document.getElementById(e);u.maxLength&&(s=u.maxLength),o=u.value,l=new RegExp("[^\\d"+r+"]","g"),i=new RegExp(r,"g"),o=o.replace(l,""),"."!==r&&(o=o.replace(i,".")),o=removeAllSpaces(o),o=trimStrg(o=(o=parseFloat(o))&&!isNaN(o)?-1<(o=String(o)).indexOf(".")||a?(o=parseFloat(o).toFixed(2),String(o).replace(/\./g,r)):parseInt(o):a?(o=parseInt("0").toFixed(2)).split(r)[0].padStart(2,"0")+r+o.split(r)[1]:parseInt("0")),void 0!==s&&s&&Number.isInteger(parseInt(s))&&0<parseInt(s)&&(o=o.substring(0,parseInt(s))),u.value=o,setElmtSelectedRangeFromData(e)}}function trimAmtElmtonpaste(e,t,n,a,r){document.getElementById(e)&&(document.getElementById(e).onpaste=function(){setTimeout(function(){trimAmtElmt(e,t,n,a,r)},10)})}function trimAmtElmtonpasteLocalFormat(e){document.getElementById(e)&&(document.getElementById(e).onpaste=function(){setTimeout(function(){trimAmtElmt(e,!1,",",!0,"."),document.getElementById(e).value=formatNumToLocal(document.getElementById(e).value,"en")},10)})}function trimAmtElmtonpasteUSAFormat(e){document.getElementById(e)&&(document.getElementById(e).onpaste=function(){setTimeout(function(){trimAmtElmt(e,!1,",",!0,"."),document.getElementById(e).value=formatNumToLocal(document.getElementById(e).value,"en")},10)})}function noPrecedingOrDoubleSpace(e){if(document.getElementById(e)){var l=document.getElementById(e);l.addEventListener("keydown",function(e){var t=l.value,n=l.value,a=n.charAt(n.length-1),r=n.charAt(0),o=(e=e||event).charCode?e.charCode:e.keyCode?e.keyCode:e.which?e.which:0;return" "!=a&&""!=n||32!==o?" "!==r&&" "!==a&&32===o?(e.preventDefault(),t=trimStrg(t),l.value=t+" ",!1):void 0:(e.preventDefault(),!1)})}}function noPrecedingSpace(t){if(document.getElementById(t)){var r=document.getElementById(t);r.addEventListener("keydown",function(t){var n=(t=t||event).charCode?t.charCode:t.keyCode?t.keyCode:t.which?t.which:0,a=String.fromCharCode(n);if(0===r.value.length&&" "==a)return e.preventDefault(),!1})}}function addURLParameter(e,t,n){var a="",r=new RegExp("^(?:[a-z]+:)/>/>/>?//","i"),o=((a=null!=n&&r.test(n)?n:location.href).indexOf("?")+1?"&":"?")+e+"="+t;return a.indexOf("#")+1?a.replace("#",o+"#"):a+o}function addURLParameterAndReload(e,t,n){if(null!=n){var a=addURLParameter(e,t,n);location.href=a}else{a=addURLParameter(e,t);location.href=a}}function removeURLParameter(e,t){var n=new RegExp("^(?:[a-z]+:)/>/>/>?//","i"),a=(null!=t&&n.test(t)?t:location.href).split("?");if(2<=a.length){for(var r=encodeURIComponent(e)+"=",o=a[1].split(/[&;]/g),l=o.length;0<l--;)/>/>/>-1!==o[l].lastIndexOf(r,0)&&o.splice(l,1);return a[0]+(0<o.length?"?"+o.join("&"):"")}return t}function removeURLParameterAndReload(e,t){if(null!=t){var n=removeURLParameter(e,t);location.href=n}else{n=removeURLParameter(e);location.href=n}}function removePrecedingProtocolFromElmtVal(e){if(document.getElementById(e)){putElmtSelectedRangeIntoData(e);var t=document.getElementById(e).value;t=(t=(t=(t=t.replace(/^(mailto:)/,"")).replace(/^(https:\/\/)/,"")).replace(/^(http:\/\/)/,"")).replace(/^(ftp:\/\/)/,""),document.getElementById(e).value=t,setElmtSelectedRangeFromData(e)}}function removeFileExt(e){return e.replace(/\.[^/.]+$/,"")}function toRomanNumerals(e){var t="";if(0==(e=parseInt(e)))return"Nulla";if(e<0&&(t+="- "),isNaN(e))return!1;e=Math.abs(e);for(var n=String(+e).split(""),a=["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM","","X","XX","XXX","XL","L","LX","LXX","LXXX","XC","","I","II","III","IV","V","VI","VII","VIII","IX"],r="",o=3;o--;)r=(a[+n.pop()+10*o]||"")+r;return t+=String(Array(+n.join("")+1).join("M")+r)}function fromRomanNumerals(e){var t,n=/[MDLV]|C[MD]?|X[CL]?|I[XV]?/g,a={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},r=0;if(!(e=String(e).toUpperCase())&&!/^M*(?:D/>/>/>?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/.test(e))return!1;for(;t=n.exec(e);)r+=a[t[0]];return parseInt(r)}function numPad2(e){return(parseFloat(e)<10?"0":"")+e}function hasClass(e,t){return e.classList?e.classList.contains(t):new RegExp("\\b"+t+"\\b","gm").test(e.className)}function addClass(e,t){hasClass(e,t)||(e.classList?e.classList.add(t):e.className+=" "+t)}function removeClass(e,t){if(hasClass(e,t))if(e.classList)e.classList.remove(t);else{var n=new RegExp("\\b"+t+"\\b","gm");e.className=e.className.replace(n,"")}}function enableDisabledElmt(e){if(document.getElementById(e)){var t=document.getElementById(e);document.getElementById(e).disabled&&(t.disabled=!1,t.removeAttribute("disabled"))}}function enableDisabledElement(e){enableDisabledElmt(e)}function enableDisabledElmts(e){if(Array.isArray(e))e.forEach(enableDisabledElmt);else{if("string"!=typeof e)return console.error("Argument/Parameter 'eids', passed to function 'enableDisabledElmts(...)' is not an array or a string."),!1;enableDisabledElmt(e)}}function formatAmountBasedOnCurrency(e,t){if(document.getElementById(e)&&document.getElementById(t)){putElmtSelectedRangeIntoData(e);var n=document.getElementById(e),a=document.getElementById(t).value;return isNaN(parseFloat(n.value))?(console.error("Error: [ amt_elmt.value ] is 'NaN' in function 'formatAmountBasedOnCurrency', in file 'dynamic_format.min.js'"),!1):(n.value="HUF"==a||"JPY"==a||"TWD"==a?Math.round(parseFloat(n.value)):Number(parseFloat(n.value)).toFixed(2),setElmtSelectedRangeFromData(e),!0)}return console.error("Error: Either [ 'eid' ] or [ 'ccy_code_eid' ] does NOT contain a valid element ID, in function 'formatAmountBasedOnCurrency', in file 'dynamic_format.min.js'"),!1}function visibleToHiddenStripeAmount(e,t){var n=document.getElementById(e),a=document.getElementById(t),r=n.value,o="100";n&&!isNaN(parseFloat(r))&&(o=100*parseFloat(r)),a.value=parseInt(o)}function pasteTextFromClipboard(e){alert("For security reasons, websites are usually not allowed to\naccess your device's clipboard (copy/paste functionality).\nSo, you'll have to paste your text manually. Here's how!\n\nTo paste text from your computer's, or device's, clipboard:\n\nMethod [ A ] :\n----------------------------------------------------\nIf you're using a computer, with a mouse or,\ntouchpad, right-click inside the text-field, and\nselect [ Paste ] from the context menu.\n\n-or-\n\nMethod [ B ] :\n----------------------------------------------------\nLeft-click inside the text-field, where you want\nto paste your text, then press [ Ctrl + V ] keys,\nsimultaneously.\n\n-or-\n\nMethod [ C ] :\n----------------------------------------------------\nOn touch-based devices (such as tablets, and phones),\nmethods vary. Try holding down your finger on the,\ntext-field, until a menu appears, then tap [ Paste ],\non that menu.\n")}function backupToCookieAndClearValue(e){var t=document.getElementById(e),n=t.value;t&&n&&setCookie(e,n),t.value=""}function backupElmtsValToItsOwnCookie(e){var t=document.getElementById(e),n=t.value;t&&n&&setCookie(e,n)}function restoreElmtsValFromItsOwnCookie(e){var t=document.getElementById(e);t&&getCookie(e)&&(t.value=getCookie(e))}function setElmtsDisplayStyle(e,t){var n=document.getElementById(e);"hidden"==t?n.style.visibility="hidden":(n.style.visibility="visible",n.style.display=t)}function saveElmtsBoolStatusToCookie(e,t){var n="1";"0"!==t&&0!=t&&"false"!=t&&!1!==t&&null!=t&&""!=t&&"off"!=t&&"no"!=t||(n="0"),document.getElementById(e)&&setCookie(e,n)}function getElmtsBoolStatusFromCookie(e){if(document.getElementById(e)&&getCookie(e))return getCookie(e)}function setPoundAsFirstChar(e){var t=document.getElementById(e);"#"!=t.value.charAt(0)&&(t.value="#"+t.value)}function showFileUploadInfo(e,t){if(n=document.getElementById(e).value)var n=n.replace(/^.*[\\\/]/,"");else n="No file selected.";document.getElementById(t).innerHTML=n}function copyElmtVal(e,t){return document.getElementById(t).value=document.getElementById(e).value,!0}function copyInnerHTMLFromElementToElement(e,t){return document.getElementById(t).innerHTML=document.getElementById(e).innerHTML,!0}function formatDynamicElement(e,t,n){var a=document.getElementById(n);a.style.display=e,a.style.overflow=t}function reverseAString(e){return(e=e.toString()).split("").reverse().join("")}function makeUpperCase(e){elmt=document.getElementById(e),elmt.value=elmt.value.toUpperCase()}function turnOffElement(e){document.getElementById(e).style.display="none",setCookie(e,"0")}function turnOnElement(e){document.getElementById(e).style.display="inline",setCookie(e,"1")}function turnOnElementBlock(e){document.getElementById(e).style.display="block",setCookie(e,"1")}function turnOffTwoElements(e,t){document.getElementById(e).style.display="none",setCookie(e,"0"),document.getElementById(t).style.display="none",setCookie(t,"0")}function turnOnTwoElements(e,t){document.getElementById(e).style.display="inline",setCookie(e,"1"),document.getElementById(t).style.display="inline",setCookie(t,"1")}function turnOnTwoElementsBlock(e,t){document.getElementById(e).style.display="block",setCookie(e,"1"),document.getElementById(t).style.display="block",setCookie(t,"1")}function updateElementsVal(e,t){document.getElementById(t).value=e}function updateElementsValReverse(e,t){document.getElementById(e).value=t}function updateElementsInnerHTML(e,t){document.getElementById(t).innerHTML=e}function resizeIFrame(e,t,n){var a=document.getElementById(e);a.style.width=t,a.style.height=n}function disableSelectAddOptionAndChooseIt(e,t,n,a){a=parseInt(Math.round(a),10);var r=!1,o=document.getElementById(e),l=document.createElement("option");l.text=t,l.value=n,""==a||null==a||"NaN"==a||a<0?a="0":a>o.length&&(a=o.length),o.disabled=!0;for(var i=0;i<o.length;i++)o.options[i].value==n&&(r=!0);0==r&&(o.add(l,o[a]),o.selectedIndex=a)}function disableSelectRemoveOptionAndChooseFirstOption(e,t){var n=document.getElementById(e);n.disabled=!0;for(var a=0;a<n.length;a++)n.options[a].value==t&&(n.remove(a),n.selectedIndex="0");n.disabled=!1}function updateTxtCookie(e){var t=document.getElementById(e).value;setCookie(e,t)}function updateVarAndCookieWithValue(e,t){document.getElementById(e).value=t,setCookie(e,t)}function updateAltCookiePlusAltElmnt(e,t){updateVarAndCookieWithValue(t,document.getElementById(e).value)}function setAltElementToOriginal(e,t){updateVarAndCookieWithValue(t,document.getElementById(e).value)}function changeImageSrc(e,t){document.getElementById(e).src=t}function recallElementStatus(e){if(getCookie(e)){var t=getCookie(e);"1"==t?turnOnElement(e):"0"==t&&turnOffElement(e)}}function setRadioButtonChecked(e){document.getElementById(e).checked=!0}function iSetCheckRadio(e){document.getElementById(e).checked=!0}function makeTextInvisible(e){document.getElementById(e).style.color="rgba(0,0,0,0.0)"}function makeTextBlack(e){document.getElementById(e).style.color="rgba(0,0,0,1.0)"}

/* 'dynamic_format.min.js' [END] */

</script>

<style>
*
	{
		color:#535353;
		font-family:Arial, Helvetica, Sans-Serif;
		font-size:15px;
		box-sizing: border-box;
	}

input
	{
		width:240px;

		margin-top:4px;
		padding:4px 6px;

		border:1px solid #BCBCBC;
	}

textarea
	{
		width:450px;
		height:150px;

		margin-top:4px;
		padding:5px 7px;

		border:1px solid #BCBCBC;

		resize:none;
	}
	
input:invalid, textarea:invalid
	{
		background-color: #FFFFFF;
	}

input:valid, textarea:valid
	{
		background-color: #DEFFDF;
	}

.bttn, button, input[type="button"], input[type="submit"], input[type="reset"] 
	{
		margin-right:20px;
	}
	
.required
	{
		color: #FF0000;
	}

</style>

</head>

<body>

<form name="ctc_form" id="ctc_form" action='#' method='post'>

<br>
<br>
<label for="vis_nm">Your Name <span class='required'>*</span> :</label>
<br>
<input type="text" name="vis_nm" id="vis_nm" maxlength="85" pattern="^(([^\d\s\W_]|[\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u017F\u1E02-\u1EF3])+){2,}(['’,\-\.]+)?(([^\d\s\W_]|[\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u017F\u1E02-\u1EF3]))*(([ ]+){0,1}((([^\d\s\W_]|[\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u017F\u1E02-\u1EF3])+){2,})(['’-,\.]+)?((([^\d\s\W_]|[\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u017F\u1E02-\u1EF3])){2,})?)*$" title="Please enter your FULL name." style='width:350px;' required>
<br>
<br>

<label for="vis_eml">Your Email <span class='required'>*</span> :</label>
<br>
<input type="text" name="vis_eml" id="vis_eml" maxlength="254" pattern="^[\w\.%\+\-][email protected][a-zA-Z0-9\.\-]+\.[^\d\W_]{2,}$" title="Please enter your FULL name." style='width:350px;' required>
<br>
<br>

<label for="phn_num">Your Phone :</label>
<br>
<input type="text" name="phn_num" id="phn_num" maxlength="16" pattern="^([1][ ]{1})?\([^\D]{3}\)[ ]{1}[^\D]{3}-[^\D]{4}$" title="Please enter your FULL name." style='width:350px;'>
<br>
<br>

<label for="vis_msg">Message :</label>
<br>
<textarea id='vis_msg' name='vis_msg' pattern=".+" style='width:350px;height:400px;' required></textarea>
<br>
<br>

<button type="submit" name="submit" id="submit">Submit</button>
<button type="reset" name="reset" id="reset">Reset</button>

</form>

<script>

document.getElementById('vis_nm').oninput = function(){autoFormatNameField(this.id);};
document.getElementById('vis_eml').oninput = function(){autoFormatEmailField(this.id);};
document.getElementById('phn_num').oninput = function(){autoFormatUSPhoneNumField(this.id);};

autoFormatNameFieldonpaste('vis_nm')
autoFormatEmailFieldonpaste('vis_eml');
autoFormatUSPhoneNumFieldonpaste('phn_num');

</script>

</body>
</html>



@modi123_1 Please do let me know what you think. :)
Was This Post Helpful? 0
  • +
  • -

#8 JamesAndersonJr   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 26
  • Joined: 03-December 13

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 10 June 2019 - 09:08 AM

@modi123_1 JSFiddle Collabo' Link
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15225
  • View blog
  • Posts: 60,941
  • Joined: 12-June 08

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 10 June 2019 - 09:16 AM

Your minified JS should be in their own files.. there are two console errors being thrown from said JS.

The error message for email textbox is about names. The titles are are about names.

Unclear why 'phone' is green.
Was This Post Helpful? 0
  • +
  • -

#10 JamesAndersonJr   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 26
  • Joined: 03-December 13

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 11 June 2019 - 12:46 AM

modi123_1 The minified JS scripts are in separate files, on my production site (I just put it all-in-one to simplify pasting/posting). But could you please explain more about the errors you've spotted? What do you mean by "about names"?
Was This Post Helpful? 0
  • +
  • -

#11 JamesAndersonJr   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 26
  • Joined: 03-December 13

Re: Why Does This RegEx Pattern Crash Nearly All Browsers Upon Testing?

Posted 11 June 2019 - 01:01 AM

BTW, don't base your response off the JS Fiddle link I posted because the way I set it up was all wrong: it allows just any arbitrary on-looker to "collaborate" or "modify" or "alter" the code, and because that's a security risk for me, I will no longer be clicking on that link. In fact, if it is within your authority or power to do so, I highly recommend removing that link altogether. At least until I can figure out how to make an anonymous JSFiddle in "read-only" mode only, or just post my code directly here on the forums, just to be safe.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1