Drewdle Posted January 26, 2011 Share Posted January 26, 2011 I'd like some help understanding how to use validation for form field characters please! if(!preg_match("/^[a-zA-Z]+$/",$_POST['fname'])) { echo "Invalid Entry"; } Now, where do I specify what characters to check? Is it this part: ("/^[a-zA-Z]+$/",$_POST['fname']) How would I add other things? I believe that allows upper and lower case letters only, how would I add things like '@' '-' '_' etc etc...would I just add them to the list inside the square brackets or is it a new set of brackets?... What about numbers? Would it be "/[0-9]/" ? Also, can I swap $_POST['fname'] with just a plain variable ($fname)?. (oh and does it need the '/' inside each quote?) Thanks! OH and also! if I was to check several fields, and if all is ok execute a script would I need to have elseif/else statements of could I have a new if statement for each and then just run the script below it? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/225691-help-understanding-entry-validation/ Share on other sites More sharing options...
BlueSkyIS Posted January 26, 2011 Share Posted January 26, 2011 http://www.google.com/search?client=safari&rls=en&q=php+regular+expressions&ie=UTF-8&oe=UTF-8 Quote Link to comment https://forums.phpfreaks.com/topic/225691-help-understanding-entry-validation/#findComment-1165316 Share on other sites More sharing options...
Drewdle Posted January 26, 2011 Author Share Posted January 26, 2011 I've read most of them...it confuses me a bit. Quote Link to comment https://forums.phpfreaks.com/topic/225691-help-understanding-entry-validation/#findComment-1165333 Share on other sites More sharing options...
Pikachu2000 Posted January 26, 2011 Share Posted January 26, 2011 As a rule, if you can use string functions instead of regex patterns, it's preferable to do so. Quote Link to comment https://forums.phpfreaks.com/topic/225691-help-understanding-entry-validation/#findComment-1165334 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.