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? Quote Link to comment Share on other sites More sharing options...
grim1208 Posted April 22, 2010 Share Posted April 22, 2010 myString.match(/your_expression/) Quote Link to comment 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?? Quote Link to comment 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 Quote Link to comment 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); Quote Link to comment 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!! 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.