mpsn Posted February 26, 2012 Share Posted February 26, 2012 Hi, if I wanted a form field in my website to have at most 90 alphabet characters, would this be approrpriate: /(a-zA-Z){90}/ Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/ Share on other sites More sharing options...
litebearer Posted February 26, 2012 Share Posted February 26, 2012 Did you test it? Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321323 Share on other sites More sharing options...
blacknight Posted February 26, 2012 Share Posted February 26, 2012 preg_match('/[^a-zA-Z]{1,90}/i',$field) should allow 1-90 letters no spaces or numbers or other none letter chars Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321338 Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 Why even bother with a regex pattern for that? if( ctype_alpha($field) && strlen($field) <91 ) Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321340 Share on other sites More sharing options...
mpsn Posted February 26, 2012 Author Share Posted February 26, 2012 preg_match('/[^a-zA-Z]{1,90}/i',$field) should allow 1-90 letters no spaces or numbers or other none letter chars but isn't the '^' inside the sqr brace mean NOT any alphabets Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321344 Share on other sites More sharing options...
mpsn Posted February 26, 2012 Author Share Posted February 26, 2012 How do I make a reg expression for email validation? This is what I have: /(\da-zA-Z)+@(\da-zA-Z)+\.(a-ZA-Z)+/ So it says, check one or more of digits, alphabets, followed by @, followed by one or more digits,alphabets, followed by '.', followed by one or more alphabets, but it's not working. I'm using a forms plugin in WordPress, and we have to enter our own reg expressions. Any help for my approach is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321352 Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 filter_var('address@domain.com', FILTER_VALIDATE_EMAIL); Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321355 Share on other sites More sharing options...
mpsn Posted February 26, 2012 Author Share Posted February 26, 2012 I'm using a WordPress Contact Forms plugin, and it expects a regular expression, so can you let me know what I'm doing wrong with my approach Cheers Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321357 Share on other sites More sharing options...
AyKay47 Posted February 26, 2012 Share Posted February 26, 2012 How do I make a reg expression for email validation? This is what I have: /(\da-zA-Z)+@(\da-zA-Z)+\.(a-ZA-Z)+/ So it says, check one or more of digits, alphabets, followed by @, followed by one or more digits,alphabets, followed by '.', followed by one or more alphabets, but it's not working. I'm using a forms plugin in WordPress, and we have to enter our own reg expressions. Any help for my approach is appreciated. That is not what that regex says at all. You do not have your characters grouped in character classes. [a-zA-Z\d] The regex that you have is not doing what you think it is, and no valid email will pass that. Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321431 Share on other sites More sharing options...
mpsn Posted February 27, 2012 Author Share Posted February 27, 2012 Then what is round brackets for, and isn't square brackets imply OR, so [a-zA-Z\d]+ would mean one or more lower case a to z OR one or more upper case A to Z OR one or more digits? Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321704 Share on other sites More sharing options...
mpsn Posted February 27, 2012 Author Share Posted February 27, 2012 I tried this, it's still now working (for email validation) /[\da-zA-Z]+@[\da-zA-Z]+\.[a-ZA-Z]+/ Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321707 Share on other sites More sharing options...
Zane Posted February 27, 2012 Share Posted February 27, 2012 Then what is round brackets for, and isn't square brackets imply OR, so [a-zA-Z\d]+ would mean one or more lower case a to z OR one or more upper case A to Z OR one or more digits? What are "round brackets"? I'm assuming you mean parentheses.... Parentheses are used to consolidate a regex search. For instance, if you wanted to go through and grab the name, class, and value as separate entities.... then you'd use parenthesis for each one. The braces do not mean OR,,, they are used for ranges.. For example [1-9A-Za-Z@%!] Would only match something that had either of the characters. 453ABCzyx@@@%!!!!! // Would match 453ABCzyx@@@%!!!!!$$ //Would not match because the $ is not within the range. 02356985 //Would not match because the numeric range is 1-9 Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321712 Share on other sites More sharing options...
mpsn Posted February 27, 2012 Author Share Posted February 27, 2012 so what am i doing wrong w. my approach for email validation: /[\da-zA-Z]+@[\da-zA-Z]+\.[a-ZA-Z]+/ Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321719 Share on other sites More sharing options...
AyKay47 Posted February 27, 2012 Share Posted February 27, 2012 That pattern will match a standard email. But will also match things like test@test.helooooooooooooooooooooo (which apparently the code in this forum will match) which clearly is not an email. Also, there are numerous characters that are valid in email addresses that you have left out of your pattern (dashes, underscores, etc..) post a sample string and your logic for matching the email address. Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1321736 Share on other sites More sharing options...
blacknight Posted February 28, 2012 Share Posted February 28, 2012 preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str); will match an email http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet-version-1/ this is a regex cheet sheet that i use explanes alot of stuff... Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1322136 Share on other sites More sharing options...
AyKay47 Posted February 28, 2012 Share Posted February 28, 2012 preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str); will match an email http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet-version-1/ this is a regex cheet sheet that i use explanes alot of stuff... not to be rude, but that is one of the grossest email regex I have seen in a while. There are so many things wrong with it that I'm not even sure where to start. That regex would match an "email" like test@test.com.com.com.com.com.com.org.co This is one I like to use: ~^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$~i depending on the context you could wrap it in word boundaries instead of anchors. Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1322139 Share on other sites More sharing options...
blacknight Posted February 29, 2012 Share Posted February 29, 2012 yes but not all eamils are just i dot extention my old school one was @unb.nb.gc.ca .... on the php manual some one cretaed this function http://www.php.net/manual/en/function.preg-match.php#105542 looks complex but validates the entier address peace by peace Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1322157 Share on other sites More sharing options...
mpsn Posted March 5, 2012 Author Share Posted March 5, 2012 i'll try it out thx Quote Link to comment https://forums.phpfreaks.com/topic/257799-preg-stuff/#findComment-1324050 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.