37. PHP Program to check given Input is Digit or UpperCase or LowerCase or Special Character.
How does this program work?
- In this program you are going to learn about how to check given Input is Digit or UpperCase or LowerCase or Special Character using PHP.
- Here we are using if-else-if conditions then we can easily get the Output.
Here is the code
<html>
<head>
<title>PHP Program To Check if input is Digit or Alphabet or Special</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="input" value="" placeholder="Enter input"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$input_char = $_POST['input']; echo "Given Input : ".$input_char;//To print given input
//There is at least one Digit inside the input
if (preg_match( '/\d/', $input_char ))
{
echo "Given input is Digit";
}
//There is at least one Upper Case Character inside the input
else
if (preg_match('/[A-Z]/', $input_char))
{
echo "Given input is Upper Case";
}
//There is at least one Lower Case Character inside the input
else
if(preg_match('/[a-z]/', $input_char) )
{
echo "Given input is Lower Case";
}
//There is at least one special Character inside the input
else
if(preg_match('/[^a-zA-Z\d]/', $input_char))
{
echo "Given input is Special Character";
}
return 0;
}
?>
</body>
</html>