gijew Posted September 11, 2006 Share Posted September 11, 2006 Hi,I'm in a posting mood today so I might as well post this as well = )I have this tiny regex guy here that (as you may see) only checks to ensure the last name has letters ONLY. I got to thinking about that and realized that there are a few O'Brians or those Irish people that like to mess me up from time to time. Anyhoo, I started trying to play around with it only to realize that I was getting nowhere.If (!preg_match('/^[a-zA-Z]+$/i', $_POST['PreQualification_First_Name'])) { // fail)I tried escaping the ' but I'm guessing there is more to it. I just want the sucker to not fail for the Irish people of the world = )Thank you! Quote Link to comment Share on other sites More sharing options...
effigy Posted September 11, 2006 Share Posted September 11, 2006 [code]<pre><?php $tests = array( 'Smith', 'Howard', "O'Brian", ); foreach ($tests as $test) { echo $test, ' => '; echo preg_match('/^(?:O\')?[A-Za-z]+$/', $test) ? 'OK' : 'Not OK' ; echo '<br/>'; }?></pre>[/code]What if there was a Smith-Howard? Quote Link to comment Share on other sites More sharing options...
gijew Posted September 11, 2006 Author Share Posted September 11, 2006 The problem with that is I dislike hyphenated names but prefer Irish people. I umm, didn't think about that. Nice catch. Quote Link to comment Share on other sites More sharing options...
gijew Posted September 11, 2006 Author Share Posted September 11, 2006 I played around with what you had a bit and started thinking some more. I'm going to throw it out but I don't know how much time you're willing to invest in this = )<?php$tests = array( 'Smith', 'Howard', 'Conan-Neil', 'Von Dutchman', 'Last, First', 'First Middle Last', 'Jason2', "O'Brian", );foreach ($tests as $test) { echo $test, ' => '; echo preg_match('/^(?:O\')?[A-Za-z -]+$/', $test) ? 'OK' : 'Not OK' ; echo '<br/>';}?>So all I did was throw a hypen and a space in there. I started to think of the different name types out there. The only name I know of that is non-Klingon that has an apostrophe is like O'Brian, O'Keefe, etc. There are names like Von Dusch or whatever. So basically can you help me limit the amount of spaces in a string to one and maybe only allow the letter "O" to follow the apostrophe? I don't know if that's too far out of the scope here or if I'm wrong on the naming convention. Quote Link to comment Share on other sites More sharing options...
effigy Posted September 12, 2006 Share Posted September 12, 2006 I'm assuming 2 letters is the shortest last name.[code]<pre><?php $tests = array( 'Smith', 'Howard', 'Conan-Neil', 'Von Dutchman', 'Last, First', 'First Middle Last', 'Jason2', "O'Brian", 'a', 'ab', 'abc', 'a-b', 'ab-a', 'ab-ab', 'a b', 'ab a', 'ab cd', ); foreach ($tests as $test) { echo $test, ' => '; echo preg_match('/ ^ ### BOL (?:O\')? ### Possible Oapostrophe. [A-Za-z]{2,} ### At least 2 letters. ([\s-])? ### Possible (white)space or hyphen. ### Require at least 2 more letters if a space or hyphen was found; ### otherwise, require any amount, even 0. (?(1)[A-Za-z]{2,}|[A-Za-z]*) $ ### EOL /x', $test) ? 'OK' : 'Not OK' ; echo '<br/>'; }?></pre>[/code][quote]Smith => OKHoward => OKConan-Neil => OKVon Dutchman => OKLast, First => Not OKFirst Middle Last => Not OKJason2 => Not OKO'Brian => OKa => Not OKab => OKabc => OKa-b => Not OKab-a => Not OKab-ab => OKa b => Not OKab a => Not OKab cd => OK[/quote] Quote Link to comment Share on other sites More sharing options...
gijew Posted September 12, 2006 Author Share Posted September 12, 2006 Everytime you've helped me you always make it way above my head so I have to learn what the hell you did. Thanks alot for teaching me. I don't remember my kids names now.Oh yeah...thanks for the help. It is very much appreciated =) 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.