[PHP] ICQ # validation
if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } Although I'm not too familiar with regexp I'd say the code validates because the icq number you are providing actually confimrs to the pattern. The first seven to nine digits contain only numbers so the pattern is true. Th ce pattern does not check the length of your provided string. If I'm correct than 123456789 This is a test will also proof to be correct. So you have to do two things first check the whole argument for digits like ereg('^[0-9]{'.strlen($_REQUEST['icqnumber']).'}', $_REQUEST['icqnumber']) and check length separatly. (U can also use [[:digit:]]) Or use the code as mentioned before. In your place I would not assume anything about the length of the icq number. Hope that helps Stefan P.S.: Please correct me if I'm wrong with the above
Re: [PHP] ICQ # validation
Well ... - the {7,9} means that the previous char/group should repeat 7 to 9 times ... - ^ means the beginning of the string - $ means the end of the string So everything, that validates, is 7 to 9 numbers. 123456789 This is a test won't validate - it contains chars instead of $ (end of string) after [0-9]{7,9} = 7 to 9 numbers. And yes, you can use something like [[:digit:]] but I must admit I don't use that much. Ales [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] . if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } Although I'm not too familiar with regexp I'd say the code validates because the icq number you are providing actually confimrs to the pattern. The first seven to nine digits contain only numbers so the pattern is true. Th ce pattern does not check the length of your provided string. If I'm correct than 123456789 This is a test will also proof to be correct. So you have to do two things first check the whole argument for digits like ereg('^[0-9]{'.strlen($_REQUEST['icqnumber']).'}', $_REQUEST['icqnumber']) and check length separatly. (U can also use [[:digit:]]) Or use the code as mentioned before. In your place I would not assume anything about the length of the icq number. Hope that helps Stefan P.S.: Please correct me if I'm wrong with the above -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ICQ # validation
Also, don't forget to escape the $ character in your expression, since it is reserved for variable declaration. Ales KrajníK [EMAIL PROTECTED] schreef in bericht news:[EMAIL PROTECTED] Well ... - the {7,9} means that the previous char/group should repeat 7 to 9 times ... - ^ means the beginning of the string - $ means the end of the string So everything, that validates, is 7 to 9 numbers. 123456789 This is a test won't validate - it contains chars instead of $ (end of string) after [0-9]{7,9} = 7 to 9 numbers. And yes, you can use something like [[:digit:]] but I must admit I don't use that much. Ales [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] . if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } Although I'm not too familiar with regexp I'd say the code validates because the icq number you are providing actually confimrs to the pattern. The first seven to nine digits contain only numbers so the pattern is true. Th ce pattern does not check the length of your provided string. If I'm correct than 123456789 This is a test will also proof to be correct. So you have to do two things first check the whole argument for digits like ereg('^[0-9]{'.strlen($_REQUEST['icqnumber']).'}', $_REQUEST['icqnumber']) and check length separatly. (U can also use [[:digit:]]) Or use the code as mentioned before. In your place I would not assume anything about the length of the icq number. Hope that helps Stefan P.S.: Please correct me if I'm wrong with the above -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ICQ # validation
Maybe I'm off my rocker, but I don't see how this can't work. I'm trying to validate an ICQ number, and assuming a valid one is between 7 and 9 numbers. My line of code is this: if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } I've submitted the ICQ # 2264532680, but it validates. Any ideas?
Re: [PHP] ICQ # validation
Use single quotes around your pattern. if(ereg('^[0-9]{7,9}$',... With the double quotes, PHP is probably seeing the $ and looking for a variable, even though it's at the end of the string. ---John Holmes... - Original Message - From: Liam Gibbs [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, March 03, 2003 2:00 PM Subject: [PHP] ICQ # validation Maybe I'm off my rocker, but I don't see how this can't work. I'm trying to validate an ICQ number, and assuming a valid one is between 7 and 9 numbers. My line of code is this: if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } I've submitted the ICQ # 2264532680, but it validates. Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ICQ # validation
On Mon, 3 Mar 2003 14:00:43 -0500, you wrote: Maybe I'm off my rocker, but I don't see how this can't work. I'm trying to validate an ICQ number, and assuming a valid one is between 7 and 9 numbers. My line of code is this: if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } I've submitted the ICQ # 2264532680, but it validates. Any ideas? if (ereg (^[0-9]{7,9}$, 2264532680)) { print (a-okay!); } else { print (error msg); } fails. I suspect you're not grabbing the variable from the environment correctly. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ICQ # validation
Does it actually NEED a regexp? UNTESTED code: ? $icq = 2264532680; if( (is_int($icq)) (strlen($icq) 7) (strlen($icq) 9) ) { echo yah; } else { echo nah; } ? FWIW, Are you SURE that all valid ICQ #'s are between 7 and 9 chars? Surely at some point they'll reach 10 chars, and *may* have started at 6? Justin on 04/03/03 6:00 AM, Liam Gibbs ([EMAIL PROTECTED]) wrote: Maybe I'm off my rocker, but I don't see how this can't work. I'm trying to validate an ICQ number, and assuming a valid one is between 7 and 9 numbers. My line of code is this: if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } I've submitted the ICQ # 2264532680, but it validates. Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] ICQ # validation
Hi, Tuesday, March 4, 2003, 12:06:14 PM, you wrote: JF Does it actually NEED a regexp? JF UNTESTED code: JF ? JF $icq = 2264532680; JF if( (is_int($icq)) (strlen($icq) 7) (strlen($icq) 9) ) { JF echo yah; JF } else { JF echo nah; JF } ? JF FWIW, Are you SURE that all valid ICQ #'s are between 7 and 9 chars? JF Surely at some point they'll reach 10 chars, and *may* have started at 6? JF Justin JF on 04/03/03 6:00 AM, Liam Gibbs ([EMAIL PROTECTED]) wrote: Maybe I'm off my rocker, but I don't see how this can't work. I'm trying to validate an ICQ number, and assuming a valid one is between 7 and 9 numbers. My line of code is this: if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } I've submitted the ICQ # 2264532680, but it validates. Any ideas? My icq is 6 digits -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] ICQ # validation
On March 3, 2003 06:31 pm, Tom Rogers wrote: Hi, Tuesday, March 4, 2003, 12:06:14 PM, you wrote: JF Does it actually NEED a regexp? JF UNTESTED code: JF ? JF $icq = 2264532680; JF if( (is_int($icq)) (strlen($icq) 7) (strlen($icq) 9) ) { JF echo yah; JF } else { JF echo nah; JF } ? JF FWIW, Are you SURE that all valid ICQ #'s are between 7 and 9 chars? JF Surely at some point they'll reach 10 chars, and *may* have started at 6? JF Justin JF on 04/03/03 6:00 AM, Liam Gibbs ([EMAIL PROTECTED]) wrote: Maybe I'm off my rocker, but I don't see how this can't work. I'm trying to validate an ICQ number, and assuming a valid one is between 7 and 9 numbers. My line of code is this: if(ereg(^[0-9]{7,9}$, $_REQUEST[icqnumber])) { print(a-okay!); } else { print(error msg); } I've submitted the ICQ # 2264532680, but it validates. Any ideas? My icq is 6 digits Would be kinda cool if your scirpt did a search on icq.com and if it found a result then the ICQ # is valid.. of course that means you're relying on the icq server to be up and the search page to stay consistant.. leo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php