anatak Posted March 16, 2007 Share Posted March 16, 2007 Hello I have a php reg ex that I want to use in javascript. I am trying to translate it to javascript but I am failing. here is the php $handle_legit = ereg("^[a-zA-Z0-9]{2,16}$", $userhandle); if(!$handle_legit){ $invalid_handle = 1; } any idea how this would look into javascript ? I was thinking something like this but I don't get the escaping right. var filter=<translated regex from php> ; if (filter.test(str)){ testresults=true; }else{ alert(text); testresults=false; kind regards anatak Link to comment https://forums.phpfreaks.com/topic/42952-solved-php-reg-ex-to-javascript/ Share on other sites More sharing options...
fenway Posted March 16, 2007 Share Posted March 16, 2007 Escaping? There shouldn't be any... var filter=/^[a-zA-Z0-9]{2,16}$/; Link to comment https://forums.phpfreaks.com/topic/42952-solved-php-reg-ex-to-javascript/#findComment-209001 Share on other sites More sharing options...
anatak Posted March 17, 2007 Author Share Posted March 17, 2007 Thank you Fenway. I was convinced it needed some escaping. it works now. Link to comment https://forums.phpfreaks.com/topic/42952-solved-php-reg-ex-to-javascript/#findComment-209208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.