Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Books
Software
Downloads
Hosting
manuals
Forums
Script directory
Training
Our Links

ADD TO Progged Progged
ADD TO DEL.ICIO.US Del.icio.
ADD TO DIGG Digg
ADD TO FURL Furl
ADD TO NEWSVINE Newsvine
ADD TO NETSCAPE Netscape
ADD TO REDDIT Reddit
ADD TO STUMBLEUPON StumbleUpon
ADD TO TECHNORATI FAVORITES Technorati
ADD TO SQUIDOO Squidoo
ADD TO WINDOWS LIVE Windows Live
ADD TO YAHOO MYWEB Yahoo MyWeb
ADD TO ASK Ask
ADD TO GOOGLE Google
ADD TO MAGNOLIA Magnolia
ADD TO SPURL Spurl



 
 

SPONSORS



 
 

Check number of characters

You want to ensure that a use has entered a password with the correct amount of characters , how would you go abou this task . Well with regular expressions this is easy. This example ensures that between 6 and 12 characters are entered , of course you can change this by altering the code . To test this out change the amount of characters entered in $str1 , have less than 6 , more than 12 , have the correct amount etc.

Code

<?php
//check the amount of characters in a string function
//Beginners PHP 2001
// http://www.beginnersphp.co.uk
Function CheckNoChars($strText)
{
//check for between 6 and 12 characters
if (eregi("^.{6,12}$" , $strText))
return true;
else
return false;
}
?>
<?php
//test the function
$str1 = "mypasswordistoolong";
if (CheckNoChars($str1))
//if its OK display this message
echo "this has the correct number of characters";
//if its not OK display this one instead
else
echo "incorrect number of characters";
?>

Example:

incorrect number of characters