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 Quote Link to comment 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}$/; Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.