Re: [PHP] preg_match help please
On Thu, 08 Sep 2005 16:36:36 +0100, Steve Turnbull wrote: > On Thu, 08 Sep 2005 09:15:03 +0100, Steve Turnbull wrote: > >> On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote: >> >>> Steve Turnbull wrote: I am trying to find a regular expression to match a variable, what I think should work (but doesn't) is; preg_match ('^/[\w],[\w],/', $variable) The $variable MUST contain an alpha-numeric string, followed by a comma, followed by another alpha-numeric string, followed by another comma followed by (but doesn't have to!!) another alpha-numeric string followed by nothing. I realise my regex above doesn't allow for the last 'followed by nothing', but to me it looks like it should match the first part of the string up to the last comma? >>> >>> Something like >>> >>> '/^\w+,\w+,\w*$/' >>> >>> maybe? (untested) >>> >>> http://php.net/reference.pcre.pattern.syntax >> >> Thats got me a lot further - thanks >> >> I reduced it slightly to '/^\w+,\w+,' because at the end there is the >> possibility of an alpha-numeric character(s) OR nothing at all with the >> exception of a possible line break (note possible) >> >> It's the 'possibly nothing at all' which I am slightly stuck on >> >> Thanks >> Steve > > > One more thing (I have tried researching myself and reading the o'rielly > book, but I need fairly swift solutions)... > > How would I check for this scenario; > > Two commas, which MAY have, but don't always have a value between, but > the commas must ALWAYS be there - i.e. > > var1,var2,var3 > var1,var2, > var1,, > No matter now - sorted. I hadn't read the final reply before I posted this one Thanks again Steve > Cheers > Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match help please
On Thu, 08 Sep 2005 09:15:03 +0100, Steve Turnbull wrote: > On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote: > >> Steve Turnbull wrote: >>> I am trying to find a regular expression to match a variable, what I think >>> should work (but doesn't) is; >>> >>> preg_match ('^/[\w],[\w],/', $variable) >>> >>> The $variable MUST contain an alpha-numeric string, followed by a comma, >>> followed by another alpha-numeric string, followed by another comma >>> followed by (but doesn't have to!!) another alpha-numeric string followed >>> by nothing. >>> >>> I realise my regex above doesn't allow for the last 'followed by nothing', >>> but to me it looks like it should match the first part of the string up to >>> the last comma? >> >> Something like >> >> '/^\w+,\w+,\w*$/' >> >> maybe? (untested) >> >> http://php.net/reference.pcre.pattern.syntax > > Thats got me a lot further - thanks > > I reduced it slightly to '/^\w+,\w+,' because at the end there is the > possibility of an alpha-numeric character(s) OR nothing at all with the > exception of a possible line break (note possible) > > It's the 'possibly nothing at all' which I am slightly stuck on > > Thanks > Steve One more thing (I have tried researching myself and reading the o'rielly book, but I need fairly swift solutions)... How would I check for this scenario; Two commas, which MAY have, but don't always have a value between, but the commas must ALWAYS be there - i.e. var1,var2,var3 var1,var2, var1,, Cheers Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match help please
On 08 September 2005 09:15, Steve Turnbull wrote: > On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote: > > > Steve Turnbull wrote: > > > I am trying to find a regular expression to match a variable, > > > what I think should work (but doesn't) is; > > > > > > preg_match ('^/[\w],[\w],/', $variable) > > > > > > The $variable MUST contain an alpha-numeric string, followed by a > > > comma, followed by another alpha-numeric string, followed by > > > another comma followed by (but doesn't have to!!) another > > > alpha-numeric string followed by nothing. > > > > > > I realise my regex above doesn't allow for the last 'followed by > > > nothing', but to me it looks like it should match the first part > > > of the string up to the last comma? > > > > Something like > > > > '/^\w+,\w+,\w*$/' > > > > maybe? (untested) > > > > http://php.net/reference.pcre.pattern.syntax > > Thats got me a lot further - thanks > > I reduced it slightly to '/^\w+,\w+,' because at the end there is the > possibility of an alpha-numeric character(s) OR nothing at > all with the > exception of a possible line break (note possible) > > It's the 'possibly nothing at all' which I am slightly stuck on The * takes care of that -- it means 0 or more of the preceding entity. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match help please
Steve Turnbull wrote: On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote: Something like '/^\w+,\w+,\w*$/' maybe? (untested) http://php.net/reference.pcre.pattern.syntax Thats got me a lot further - thanks I reduced it slightly to '/^\w+,\w+,' because at the end there is the possibility of an alpha-numeric character(s) OR nothing at all with the exception of a possible line break (note possible) It's the 'possibly nothing at all' which I am slightly stuck on That's what the \w* means. That means "0 or more word-characters", as opposed to \w+ which means "1 or more word-characters. The $ after that means "end of string" which makes sure that it's the last thing in the string. In other words, \w* means some word-characters, or nothing at all. You'd need to handle the newline in much the same way. The URL I gave you should help out a lot with that. -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ If you find my advice useful, please consider donating to a poor student! You can choose whatever amount you think my advice was worth to you. http://tinyurl.com/7oa5s -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match help please
On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote: > Steve Turnbull wrote: >> I am trying to find a regular expression to match a variable, what I think >> should work (but doesn't) is; >> >> preg_match ('^/[\w],[\w],/', $variable) >> >> The $variable MUST contain an alpha-numeric string, followed by a comma, >> followed by another alpha-numeric string, followed by another comma >> followed by (but doesn't have to!!) another alpha-numeric string followed >> by nothing. >> >> I realise my regex above doesn't allow for the last 'followed by nothing', >> but to me it looks like it should match the first part of the string up to >> the last comma? > > Something like > > '/^\w+,\w+,\w*$/' > > maybe? (untested) > > http://php.net/reference.pcre.pattern.syntax Thats got me a lot further - thanks I reduced it slightly to '/^\w+,\w+,' because at the end there is the possibility of an alpha-numeric character(s) OR nothing at all with the exception of a possible line break (note possible) It's the 'possibly nothing at all' which I am slightly stuck on Thanks Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match help please
Steve Turnbull wrote: I am trying to find a regular expression to match a variable, what I think should work (but doesn't) is; preg_match ('^/[\w],[\w],/', $variable) The $variable MUST contain an alpha-numeric string, followed by a comma, followed by another alpha-numeric string, followed by another comma followed by (but doesn't have to!!) another alpha-numeric string followed by nothing. I realise my regex above doesn't allow for the last 'followed by nothing', but to me it looks like it should match the first part of the string up to the last comma? Something like '/^\w+,\w+,\w*$/' maybe? (untested) http://php.net/reference.pcre.pattern.syntax -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ If you find my advice useful, please consider donating to a poor student! You can choose whatever amount you think my advice was worth to you. http://tinyurl.com/7oa5s -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match help please
Hi I am trying to find a regular expression to match a variable, what I think should work (but doesn't) is; preg_match ('^/[\w],[\w],/', $variable) The $variable MUST contain an alpha-numeric string, followed by a comma, followed by another alpha-numeric string, followed by another comma followed by (but doesn't have to!!) another alpha-numeric string followed by nothing. I realise my regex above doesn't allow for the last 'followed by nothing', but to me it looks like it should match the first part of the string up to the last comma? Help appreciated, and apologies if this isn't strictly the correct group. Thanks Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
On Thu, 2005-07-28 at 19:45 +0800, Jason Wong wrote: > On Thursday 28 July 2005 01:50, André Medeiros wrote: > > > You can have four words to describe a first and last name... you can > > have other alphabets, like arabian, chinese, etc... inserting accented > > characters alone would make that a big, nasty regex, let alone > > predicting ways you can describe first/last names. > > > > I'm not saying that I have the _BEST_ sollution. All I'm saying is that > > there are sittuations that are out of your control, and it seems to me > > this might be the easiest way out, guaranteeing that there are at least > > two words. > > Most Chinese would enter their name (usually 3 words, sometimes 2. rarely > 4) WITHOUT any spaces. > > Not sure what the OP was trying to do, but the best way to handle it > (IMHO) is to give the user 2 input boxes, one for family name, the other > for the rest of their name. > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > -- > Search the list archives before you post > http://marc.theaimsgroup.com/?l=php-general > -- > New Year Resolution: Ignore top posted posts > Heh... that's the best answer i've seen so far =) That and the regexp's idea given by John (ie. forbid chars instead of entering every letter of every alphabet) would work great. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
On Thursday 28 July 2005 01:50, André Medeiros wrote: > You can have four words to describe a first and last name... you can > have other alphabets, like arabian, chinese, etc... inserting accented > characters alone would make that a big, nasty regex, let alone > predicting ways you can describe first/last names. > > I'm not saying that I have the _BEST_ sollution. All I'm saying is that > there are sittuations that are out of your control, and it seems to me > this might be the easiest way out, guaranteeing that there are at least > two words. Most Chinese would enter their name (usually 3 words, sometimes 2. rarely 4) WITHOUT any spaces. Not sure what the OP was trying to do, but the best way to handle it (IMHO) is to give the user 2 input boxes, one for family name, the other for the rest of their name. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- New Year Resolution: Ignore top posted posts -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
André Medeiros wrote: On Wed, 2005-07-27 at 12:30 -0400, John Nichel wrote: André Medeiros wrote: On Wed, 2005-07-27 at 11:55 -0400, John Nichel wrote: André Medeiros wrote: That's not very nice of you, saying that to people who try to help ;) if( strpos( $_POST['frmName'], ' ' ) === false ) { // Do error handling here } else { // All is OK :) } How does that match "Firstname Lastname" better than a regex? That will return true as long as there is at least one space, no matter what the rest of the submission is. I could submit "$^^&$& )([EMAIL PROTECTED]", or I could submit just a single space, and that would return true. strpos() has it's uses, but this isn't one of them. There is a large number of sittuations that the regex won't work in. Special characters aren't included (from what I can understand using my weak regex knowlege), you could even be chinese, and it wouldn't work. If you use strpos with trim and strlen cleverlly, you won't have to worry about it again. My $0.02 You can trim whitespace and check the length until the cows come home, and that still won't stop a string such as "#T*& [EMAIL PROTECTED]". A regex can cover practicaly every situation for a name submission; it all depends on how deep you want to validate. strpos() has too narrow of a scope to match a complex pattern. You can have four words to describe a first and last name... you can have other alphabets, like arabian, chinese, etc... inserting accented characters alone would make that a big, nasty regex, let alone predicting ways you can describe first/last names. And this can all be matched with a regex. Like I said, it depends on how deep you want to validate. I'm not saying that I have the _BEST_ sollution. All I'm saying is that there are sittuations that are out of your control, and it seems to me this might be the easiest way out, guaranteeing that there are at least two words. But it doesn't even guarantee that. As shown previously, it will return true even on strings that have non-word characters in them (no matter the language). The only thing you're guaranteeing with strpos ( $string, " " ); is that the string contains a space...that's it; and basically that's what you're limited too, until you start running other functions to check/remove other parts of the string If you find a way to fit accented characters / other alphabets there nicelly, be my guest :) It's really quite easy, when you look at it from the other direction. When you're trying to match a pattern that can contain just about anything and be considered valid, it might be best to check for characters that you _do not_ want in there. With that in mind, there's no reason to build a regex that can account for every possible alphabet and/or accents. Make sure it contains a space, but doesn't contain characters we don't want (such as [EMAIL PROTECTED]). -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
On Wed, 2005-07-27 at 12:30 -0400, John Nichel wrote: > André Medeiros wrote: > > On Wed, 2005-07-27 at 11:55 -0400, John Nichel wrote: > > > >>André Medeiros wrote: > >> > >>>That's not very nice of you, saying that to people who try to help ;) > >>> > >>>if( strpos( $_POST['frmName'], ' ' ) === false ) { > >>>// Do error handling here > >>>} else { > >>>// All is OK :) > >>>} > >>> > >> > >>How does that match "Firstname Lastname" better than a regex? That will > >>return true as long as there is at least one space, no matter what the > >>rest of the submission is. I could submit "$^^&$& )([EMAIL > >>PROTECTED]", or I > >>could submit just a single space, and that would return true. strpos() > >>has it's uses, but this isn't one of them. > > > > There is a large number of sittuations that the regex won't work in. > > Special characters aren't included (from what I can understand using my > > weak regex knowlege), you could even be chinese, and it wouldn't work. > > > > If you use strpos with trim and strlen cleverlly, you won't have to > > worry about it again. > > > > My $0.02 > > You can trim whitespace and check the length until the cows come home, > and that still won't stop a string such as "#T*& [EMAIL PROTECTED]". A regex > can > cover practicaly every situation for a name submission; it all depends > on how deep you want to validate. strpos() has too narrow of a scope to > match a complex pattern. > > -- > John C. Nichel > ÜberGeek > KegWorks.com > 716.856.9675 > [EMAIL PROTECTED] > You can have four words to describe a first and last name... you can have other alphabets, like arabian, chinese, etc... inserting accented characters alone would make that a big, nasty regex, let alone predicting ways you can describe first/last names. I'm not saying that I have the _BEST_ sollution. All I'm saying is that there are sittuations that are out of your control, and it seems to me this might be the easiest way out, guaranteeing that there are at least two words. If you find a way to fit accented characters / other alphabets there nicelly, be my guest :) Take care. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
André Medeiros wrote: On Wed, 2005-07-27 at 11:55 -0400, John Nichel wrote: André Medeiros wrote: That's not very nice of you, saying that to people who try to help ;) if( strpos( $_POST['frmName'], ' ' ) === false ) { // Do error handling here } else { // All is OK :) } How does that match "Firstname Lastname" better than a regex? That will return true as long as there is at least one space, no matter what the rest of the submission is. I could submit "$^^&$& )([EMAIL PROTECTED]", or I could submit just a single space, and that would return true. strpos() has it's uses, but this isn't one of them. There is a large number of sittuations that the regex won't work in. Special characters aren't included (from what I can understand using my weak regex knowlege), you could even be chinese, and it wouldn't work. If you use strpos with trim and strlen cleverlly, you won't have to worry about it again. My $0.02 You can trim whitespace and check the length until the cows come home, and that still won't stop a string such as "#T*& [EMAIL PROTECTED]". A regex can cover practicaly every situation for a name submission; it all depends on how deep you want to validate. strpos() has too narrow of a scope to match a complex pattern. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
On Wed, 2005-07-27 at 11:55 -0400, John Nichel wrote: > André Medeiros wrote: > > That's not very nice of you, saying that to people who try to help ;) > > > > if( strpos( $_POST['frmName'], ' ' ) === false ) { > > // Do error handling here > > } else { > > // All is OK :) > > } > > > > How does that match "Firstname Lastname" better than a regex? That will > return true as long as there is at least one space, no matter what the > rest of the submission is. I could submit "$^^&$& )([EMAIL PROTECTED]", > or I > could submit just a single space, and that would return true. strpos() > has it's uses, but this isn't one of them. > > -- > John C. Nichel > ÜberGeek > KegWorks.com > 716.856.9675 > [EMAIL PROTECTED] > There is a large number of sittuations that the regex won't work in. Special characters aren't included (from what I can understand using my weak regex knowlege), you could even be chinese, and it wouldn't work. If you use strpos with trim and strlen cleverlly, you won't have to worry about it again. My $0.02 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match - help please
From: André Medeiros [mailto:[EMAIL PROTECTED] > On Wed, 2005-07-27 at 11:41 -0400, Mike Johnson wrote: > > From: André Medeiros [mailto:[EMAIL PROTECTED] > > > > > On Wed, 2005-07-27 at 16:16 +0100, Mark Rees wrote: > > > > > > > Or even four - like Rafael van der Vaart for example - so > > > make sure that the > > > > surname box matches spaces as well, and special characters > > > like the ê, as > > > > well as ' as in John O'Kane > > > > > > > > > > Yeah, that's why strpos will make his life much easier :) > > > > Can you explain how you'd use strpos() in this situation? I > was going to ask earlier, but didn't bother, but now I'm curious... > > > > That's not very nice of you, saying that to people who try to help ;) Well, it could be argued that an obtuse link to the online docs and nothing else isn't "trying to help." ;) > if( strpos( $_POST['frmName'], ' ' ) === false ) { > // Do error handling here > } else { > // All is OK :) > } Gotcha. Except that it'll accept a ' ' string as valid. :P -- Mike Johnson Smarter Living, Inc. Web Developerwww.smartertravel.com [EMAIL PROTECTED] (617) 886-5539 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
André Medeiros wrote: That's not very nice of you, saying that to people who try to help ;) if( strpos( $_POST['frmName'], ' ' ) === false ) { // Do error handling here } else { // All is OK :) } How does that match "Firstname Lastname" better than a regex? That will return true as long as there is at least one space, no matter what the rest of the submission is. I could submit "$^^&$& )([EMAIL PROTECTED]", or I could submit just a single space, and that would return true. strpos() has it's uses, but this isn't one of them. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match - help please
On Wed, 2005-07-27 at 11:41 -0400, Mike Johnson wrote: > From: André Medeiros [mailto:[EMAIL PROTECTED] > > > On Wed, 2005-07-27 at 16:16 +0100, Mark Rees wrote: > > > > > Or even four - like Rafael van der Vaart for example - so > > make sure that the > > > surname box matches spaces as well, and special characters > > like the ê, as > > > well as ' as in John O'Kane > > > > > > > Yeah, that's why strpos will make his life much easier :) > > Can you explain how you'd use strpos() in this situation? I was going to ask > earlier, but didn't bother, but now I'm curious... > That's not very nice of you, saying that to people who try to help ;) if( strpos( $_POST['frmName'], ' ' ) === false ) { // Do error handling here } else { // All is OK :) } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match - help please
From: André Medeiros [mailto:[EMAIL PROTECTED] > On Wed, 2005-07-27 at 16:16 +0100, Mark Rees wrote: > > > Or even four - like Rafael van der Vaart for example - so > make sure that the > > surname box matches spaces as well, and special characters > like the ê, as > > well as ' as in John O'Kane > > > > Yeah, that's why strpos will make his life much easier :) Can you explain how you'd use strpos() in this situation? I was going to ask earlier, but didn't bother, but now I'm curious... -- Mike Johnson Smarter Living, Inc. Web Developerwww.smartertravel.com [EMAIL PROTECTED] (617) 886-5539 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
On Wed, 2005-07-27 at 16:16 +0100, Mark Rees wrote: > "André Medeiros" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > On Wed, 2005-07-27 at 15:27 +0100, Steve Turnbull wrote: > > > Hi > > > > > > I want to see that a user is submiting a form field in the correct > manner. > > > So I decided to use preg_match to verify their input. > > > > > > The pattern I am trying to match is; > > > > > > Firstname Secondname > > > > > > I am not bothered about character length just yet (but advise on this > would > > > be appreciated if it can be done with a regular expression - saves extra > > > checking code), but I would like case sensitity. > > > > > > The code I haev so far, which doesn't seem to work is; > > > > > > $un = $_REQUEST['name']; > > > $exp = '/^\b[a-zA-Z] [a-zA-Z]$/'; > > > > > > if (preg_match($exp, $un)) { > > > //has this matched? > > > echo "matched"; > > > } > > > > > > Help would be greatly appreciated > > > > > > Thanks > > > Steve > > > > > > > A reminder... sometimes First and Last name can contain three words. > > There are portuguese names, like "Inês de Medeiros". Watch out for that > > too. > > Or even four - like Rafael van der Vaart for example - so make sure that the > surname box matches spaces as well, and special characters like the ê, as > well as ' as in John O'Kane > Yeah, that's why strpos will make his life much easier :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
"André Medeiros" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Wed, 2005-07-27 at 15:27 +0100, Steve Turnbull wrote: > > Hi > > > > I want to see that a user is submiting a form field in the correct manner. > > So I decided to use preg_match to verify their input. > > > > The pattern I am trying to match is; > > > > Firstname Secondname > > > > I am not bothered about character length just yet (but advise on this would > > be appreciated if it can be done with a regular expression - saves extra > > checking code), but I would like case sensitity. > > > > The code I haev so far, which doesn't seem to work is; > > > > $un = $_REQUEST['name']; > > $exp = '/^\b[a-zA-Z] [a-zA-Z]$/'; > > > > if (preg_match($exp, $un)) { > > //has this matched? > > echo "matched"; > > } > > > > Help would be greatly appreciated > > > > Thanks > > Steve > > > > A reminder... sometimes First and Last name can contain three words. > There are portuguese names, like "Inês de Medeiros". Watch out for that > too. Or even four - like Rafael van der Vaart for example - so make sure that the surname box matches spaces as well, and special characters like the ê, as well as ' as in John O'Kane -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
On Wed, 2005-07-27 at 15:27 +0100, Steve Turnbull wrote: > Hi > > I want to see that a user is submiting a form field in the correct manner. > So I decided to use preg_match to verify their input. > > The pattern I am trying to match is; > > Firstname Secondname > > I am not bothered about character length just yet (but advise on this would > be appreciated if it can be done with a regular expression - saves extra > checking code), but I would like case sensitity. > > The code I haev so far, which doesn't seem to work is; > > $un = $_REQUEST['name']; > $exp = '/^\b[a-zA-Z] [a-zA-Z]$/'; > > if (preg_match($exp, $un)) { > //has this matched? > echo "matched"; > } > > Help would be greatly appreciated > > Thanks > Steve > A reminder... sometimes First and Last name can contain three words. There are portuguese names, like "Inês de Medeiros". Watch out for that too. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
On Wed, 2005-07-27 at 15:27 +0100, Steve Turnbull wrote: > Hi > > I want to see that a user is submiting a form field in the correct manner. > So I decided to use preg_match to verify their input. > > The pattern I am trying to match is; > > Firstname Secondname > > I am not bothered about character length just yet (but advise on this would > be appreciated if it can be done with a regular expression - saves extra > checking code), but I would like case sensitity. > > The code I haev so far, which doesn't seem to work is; > > $un = $_REQUEST['name']; > $exp = '/^\b[a-zA-Z] [a-zA-Z]$/'; > > if (preg_match($exp, $un)) { > //has this matched? > echo "matched"; > } > > Help would be greatly appreciated > > Thanks > Steve > http://pt.php.net/strpos -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match - help please
Steve Turnbull wrote: Hi I want to see that a user is submiting a form field in the correct manner. So I decided to use preg_match to verify their input. The pattern I am trying to match is; Firstname Secondname I am not bothered about character length just yet (but advise on this would be appreciated if it can be done with a regular expression - saves extra checking code), but I would like case sensitity. The code I haev so far, which doesn't seem to work is; $un = $_REQUEST['name']; $exp = '/^\b[a-zA-Z] [a-zA-Z]$/'; if (preg_match($exp, $un)) { //has this matched? echo "matched"; } Help would be greatly appreciated /^[a-zA-Z]{1,}\s[a-zA-Z]{1,}$/ -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match - help please
Hi I want to see that a user is submiting a form field in the correct manner. So I decided to use preg_match to verify their input. The pattern I am trying to match is; Firstname Secondname I am not bothered about character length just yet (but advise on this would be appreciated if it can be done with a regular expression - saves extra checking code), but I would like case sensitity. The code I haev so far, which doesn't seem to work is; $un = $_REQUEST['name']; $exp = '/^\b[a-zA-Z] [a-zA-Z]$/'; if (preg_match($exp, $un)) { //has this matched? echo "matched"; } Help would be greatly appreciated Thanks Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php