ATTN PHP guru's

Mirlyn

Well-Known Member
I have a form for input by the user to reset account passwords. It consists of three fields, one is a user name, one is their SSN, the third is their student ID. Is there a function in PHP to ensure the input is all letters and/or all numbers? That way I can make sure the reset script runs with a UID of all letters, and their SSN/IDs of all numbers. :)

Thanks all!
 
Code:
for($cont=0,$leng=strlen($stringtover);$cont<$leng;$cont++)
{
      if((($stringtover[$cont]>='a' && $stringtover[$cont]<='z') || ($stringtover[$cont]>='A' && $stringtover[$cont]<='Z')) != 1)
             return -1; /* a non alphabetical  character was found */
}
return 0; /* Only alphabetical string */

I just did that, that's C code with php style variables, it might be flawed.
 
sweet.....I am in much debt to you Luis ;) Thankyas!

still trying to get this PHP down....I really like it so far. :headbang:
 
the idea is the same, though :).....I think I can get it to work. Thats kinda what I was leaning towards, just wasn't sure if there was a predefined function to do it or not.

Thanks again!
 
if (is_int($ssnid)) { echo "$ssnid is an integer"; }

^^^ May need to require input without dashes for this to work

if (is_string($uid)) { echo "$uid is a string"; }

^^^ This will trigger even if it contains numbers but at least one letter, so maybe for this one try the one below

if (!preg_match('/{0-9}/', $uid)) { echo "$uid does not contain numbers"; }

^^^ Example: user enters "1ZE53" - script finds whether the string does NOT match the regular expression - note the ! before preg_match(. /{0-9}/ means "if the variable contains any instance of any character ranging from 0 and 9, it is a match". 1ZE53 will match. 13519 will match. ZERTIAGKASJDF will not match, and it will proceed with the line(s) of code between the brackets.
 
ohh, i didn't know (remember??) that php had support for regular expressions. Very usefull stuff.
 
fury said:
if (is_int($ssnid)) { echo "$ssnid is an integer"; }

^^^ May need to require input without dashes for this to work

if (is_string($uid)) { echo "$uid is a string"; }

^^^ This will trigger even if it contains numbers but at least one letter, so maybe for this one try the one below

if (!preg_match('/{0-9}/', $uid)) { echo "$uid does not contain numbers"; }

^^^ Example: user enters "1ZE53" - script finds whether the string does NOT match the regular expression - note the ! before preg_match(. /{0-9}/ means "if the variable contains any instance of any character ranging from 0 and 9, it is a match". 1ZE53 will match. 13519 will match. ZERTIAGKASJDF will not match, and it will proceed with the line(s) of code between the brackets.

None of these seem to work...
 
Try before the $ssnid line, this:

$ssnid = (int)$ssnid;

and changing the if line to this:

if ($ssnid > 0) { echo "$ssnid is an integer greater than 0"; }

If the $ssnid was entered as a string, the (int)$ssnid converts it to 0. If it's already an integer, it does nothing to it.

and try changing the preg line to this:

if (preg_match('/^{0-9}/', $uid)) {
 
Okay, I think I found my problem....integer-type variables apparantly won't go over ten digits. :retard:

Gotta rethink this for a few minutes....

Is there a way I can retrieve characters individually in a string without having to use arrays? Like CharAt in Java?
 
Back
Top