robert_gsfame Posted April 22, 2010 Share Posted April 22, 2010 i want to validate text where user has to input at least one letter if in php we have if(!ereg('[a-z]',string)){echo "wrong input";} how bout in Javascript? Link to comment https://forums.phpfreaks.com/topic/199361-ereg-in-javascript/ Share on other sites More sharing options...
grim1208 Posted April 22, 2010 Share Posted April 22, 2010 myString.match(/your_expression/) Link to comment https://forums.phpfreaks.com/topic/199361-ereg-in-javascript/#findComment-1046310 Share on other sites More sharing options...
robert_gsfame Posted April 22, 2010 Author Share Posted April 22, 2010 what if i want to check if string contain a-z or A-Z?? Link to comment https://forums.phpfreaks.com/topic/199361-ereg-in-javascript/#findComment-1046315 Share on other sites More sharing options...
grim1208 Posted April 22, 2010 Share Posted April 22, 2010 var exp = "/^[a-zA-z]$/"; var mystring = "Apple"; if(!(mystring.match(exp))) { return false; } else { return true; } code not tested Link to comment https://forums.phpfreaks.com/topic/199361-ereg-in-javascript/#findComment-1046316 Share on other sites More sharing options...
salathe Posted April 22, 2010 Share Posted April 22, 2010 You can also do: var lettersOnly = /^[a-z]+$/i.test(subject); Link to comment https://forums.phpfreaks.com/topic/199361-ereg-in-javascript/#findComment-1046337 Share on other sites More sharing options...
robert_gsfame Posted April 22, 2010 Author Share Posted April 22, 2010 Thx a lot for all helps!! Link to comment https://forums.phpfreaks.com/topic/199361-ereg-in-javascript/#findComment-1046407 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.