expresiones regulares php

  • tiffix
  • Student
  • Student
  • Avatar de Usuario
  • Registrado: Jun 03, 2009
  • Mensajes: 65
  • Loc: kenya
  • Status: Offline

Nota Abril 11th, 2011, 8:18 am

amabilidad en cualquier lugar me ayude a cómo voy a usar PHP para comprobar en la contraseña introducida tiene letras y números. gracias :(
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Abril 11th, 2011, 8:18 am

  • cesaro
  • Novice
  • Novice
  • Avatar de Usuario
  • Registrado: Jul 29, 2008
  • Mensajes: 18
  • Loc: DNSEURO.COM
  • Status: Offline

Nota Abril 11th, 2011, 11:33 pm

PHP Código: [ 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
  • Avatar de Usuario
  • Registrado: Jul 29, 2008
  • Mensajes: 18
  • Loc: DNSEURO.COM
  • Status: Offline

Nota Abril 12th, 2011, 1:37 am

El ejemplo siguiente comprueba si la contraseña debe tener al menos 8 caracteres y debe contener al menos una letra minúscula, una letra mayúscula y un dígito:
PHP Código: [ 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
  • Avatar de Usuario
  • Registrado: Jul 29, 2008
  • Mensajes: 18
  • Loc: DNSEURO.COM
  • Status: Offline

Nota Diciembre 31st, 2011, 2:42 am

Esta función para comprobar entradas numéricas del alfabeto:
PHP Código: [ 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.  

Publicar Información

  • Total de mensajes en este tema: 4 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 171 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC