regex - Debugging a Javascript RegExp Regular Expression: Validation Hangs on Amazon URL -


in using javascript validate url, used following code so answer:

function validateurl(textval) {           var urlregex = new regexp(                 "^(http|https|ftp)\://([a-za-z0-9\.\-]+(\:[a-za-z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-za-z0-9\-]+\.)*[a-za-z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-za-z]{2}))(\:[0-9]+)*(/($|[a-za-z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$");           return urlregex.test(textval);         } 

this function works fine urls tried, on following amazon url (ironically) creating mobile apps jquery mobile book, hangs. in chrome dev tools see nothing clicking anywhere inside tab doesn't anything.

http://www.amazon.com/gp/product/178216006x/ref=s9_simh_gw_p351_d3_i4?pf_rd_m=atvpdkikx0der&pf_rd_s=center-2&pf_rd_r=0sdc8sed1n96xpk44vd2&pf_rd_t=101&pf_rd_p=1389517282&pf_rd_i=507846 

the url pretty long there's nothing special in there can tell. in fact passes javascript validation on following scott's playground page.

my question not how url validation in javascript. question following: if use javascript regular expression , hangs on piece of text, makes regular expression freeze browser this? how can catch cases that?

is happens new regexp(...) vs /regex/ mentioned in this answer?

in terms of actual validation, switch different /regex/ still wanted post question because led pretty painful debugging process. (then again, tries validate urls or emails regular expressions painful).

this seems happens new regexp(...) , not /regex/ regular expression. url validation , other types of regex matching, use:

function validfoo(value) {     return /foo/i.test(value); } 

where foo regular expression.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -