Skip to content

Instantly share code, notes, and snippets.

@jabarrioss
Last active April 26, 2021 18:30
Show Gist options
  • Save jabarrioss/26e4547a503bb51d607d89cf4d4c3864 to your computer and use it in GitHub Desktop.
Save jabarrioss/26e4547a503bb51d607d89cf4d4c3864 to your computer and use it in GitHub Desktop.
Simple form validation for a random guy in the internet
<?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