Last active
April 26, 2021 18:30
-
-
Save jabarrioss/26e4547a503bb51d607d89cf4d4c3864 to your computer and use it in GitHub Desktop.
Simple form validation for a random guy in the internet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function validarform(){ | |
$mensaje = "error"; | |
if(isset($_POST["Enviar"])){ | |
$variablex = $_POST["variablex"]; | |
if(empty($variablex)){ | |
$mensaje = "Debes introducir el valor de x"; | |
} | |
if($variablex <=0){ | |
$mensaje = "El valor de x no puede ser cero"; | |
} | |
if(!preg_match("/^([0-9)+\.+[0-9]|[0-9])+$/", $variablex)){ | |
$mensaje = "Solo se permiten numeros para x"; | |
} | |
if(empty($variablex)){ | |
$mensaje = "Los datos introducidos de X son validos"; | |
} | |
} | |
return $mensaje; | |
} | |
echo validarform(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment