I have a written a piece of code which accepts an input from the user and inserts it into the Data Base. The HTML code is as follows:
<td align="center"><textarea class="txt" required=required rows="3" name="Xschool" cols="30"></textarea></td>
And I need to check the data whether is has any special symbols. I used Regular Expression for it and is as follows:
$Xschool=$_POST['Xschool'];
$pattern = '/[A-Z ]+$/';
$Xschool=strtoupper($Xschool);
if(!preg_match($pattern,$Xschool))
{
echo "<pre>We are sorry. The X School ".$Xschool." is invalid. Make sure your name contains no special symbols/numbers.</pre>";
exit;
}
This code works correctly for many types of inputs but is not working for the input ST MARY'S
. When a ' symbol is encountered the code doesn't work well. What should I do to overcome this? Please help me!! Thanks in advance.