php regular expression

  • tiffix
  • Student
  • Student
  • User avatar
  • Posts: 65
  • Loc: kenya

Post 3+ Months Ago

kindly anywhere help me figure how am going to use php to verify in the entered password has got both letters and number. thanks :(
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • cesaro
  • Novice
  • Novice
  • User avatar
  • Posts: 18
  • Loc: DNSEURO.COM

Post 3+ Months Ago

PHP Code: [ Select ]
<?php
// $passwd = your varible
if(preg_match('/[^0-9A-Za-z]/',$passwd)) {
 echo 'this is a password as you want';
} else {
 echo 'you dislike this format of password';
}
?>
 
  1. <?php
  2. // $passwd = your varible
  3. if(preg_match('/[^0-9A-Za-z]/',$passwd)) {
  4.  echo 'this is a password as you want';
  5. } else {
  6.  echo 'you dislike this format of password';
  7. }
  8. ?>
  9.  
  • cesaro
  • Novice
  • Novice
  • User avatar
  • Posts: 18
  • Loc: DNSEURO.COM

Post 3+ Months Ago

The example below checks if the password must be at least 8 characters and must contain at least one lower case letter, one upper case letter and one digit:
PHP Code: [ Select ]
<?php
$password = "Fyfjk34sdfjfsjq7";
 
if (preg_match("/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password)) {
    echo "Your passwords is strong.";
} else {
    echo "Your password is weak.";
}
?>
 
  1. <?php
  2. $password = "Fyfjk34sdfjfsjq7";
  3.  
  4. if (preg_match("/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password)) {
  5.     echo "Your passwords is strong.";
  6. } else {
  7.     echo "Your password is weak.";
  8. }
  9. ?>
  10.  
  • cesaro
  • Novice
  • Novice
  • User avatar
  • Posts: 18
  • Loc: DNSEURO.COM

Post 3+ Months Ago

This function to check alphabet numeric input:
PHP Code: [ Select ]
function is_alphanum($input) {
   $regexp = "/^[0-9A-Za-z]+$/";
   if(preg_match($regexp, $input)) { return true; }
   else { return false; }
}
 
  1. function is_alphanum($input) {
  2.    $regexp = "/^[0-9A-Za-z]+$/";
  3.    if(preg_match($regexp, $input)) { return true; }
  4.    else { return false; }
  5. }
  6.  

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 100 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.