robert_gsfame Posted June 8, 2010 Share Posted June 8, 2010 How can i show the alert once text doesn't consist of number and alphabet using RegExp? thx Quote Link to comment Share on other sites More sharing options...
Adam Posted June 8, 2010 Share Posted June 8, 2010 var str = '££$%£'; if (str.match(/^[^a-zA-Z0-9]+$/)) { alert("doesn't contain alphanumeric"); } Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted June 8, 2010 Author Share Posted June 8, 2010 what i want is a text must consist of a combination of letter and number....if one missing then alert(), Quote Link to comment Share on other sites More sharing options...
Adam Posted June 8, 2010 Share Posted June 8, 2010 Yeah? var str = '££$%£'; if (str.match(/^[^a-zA-Z0-9]+$/)) { alert("this field must contain only alphanumerical characters"); } Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted June 8, 2010 Author Share Posted June 8, 2010 there is nothing to do with alphanumeric....i just want to check that a text must at least has both number and letter...therefore it is also allowed to have special characters in the text Quote Link to comment Share on other sites More sharing options...
Adam Posted June 8, 2010 Share Posted June 8, 2010 Well perhaps you should be clearer in future? You're English isn't exactly perfect. Anyway, first idea that comes to mind: var str = '£$ewe£$1556£$%£'; if (!str.match(/([a-z].*[0-9]|[0-9].*[a-z])$/i)) { alert("this field must contain at least 1 number and 1 letter"); } Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted June 8, 2010 Author Share Posted June 8, 2010 Thx so much mr Adam.....it works perfect!!!! what is actually the last part of the pattern used for $/i can give me some short explanation ? :P Quote Link to comment Share on other sites More sharing options...
Adam Posted June 8, 2010 Share Posted June 8, 2010 Actually I didn't mean to leave the $ in there, that matches the end of the string - you'll want to remove that. The "i" on the outside of the delimiters is the case-insensitive modifier, basically means the same as: /([a-zA-Z].*[0-9]|[0-9].*[a-zA-Z])/ Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted June 8, 2010 Author Share Posted June 8, 2010 :D okay! again thx for your help!!! 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.