HTML for address field:
<p> <label for="username">Address:</label>
<input type=text name="address" placeholder="Enter your address">
</p>
I have to check the address entered by the user against these conditions given below:
I think you are looking for html5 input field restrictors. But there exists one only for email address or url address, not for a regular physical address
https://www.w3schools.com/html/html_form_input_types.asp
<form>
E-mail:
<input type="email" name="email">
</form>
<form>
Add your homepage:
<input type="url" name="homepage">
</form>
based on your updated restrictions. This is best done with regular expressions
I have to check the address entered by the user against these conditions given below: 1) Only letters, numbers, hash, comma, circular brackets, forward slash, dot and hyphen are allowed. 2) Starting and ending should not be special characters. 3) Two consecutive special characters are not allowed.
This is the regex you need
/^([a-zA-Z0-9 ]|[a-zA-Z0-9 ][-#,()\/.])*[a-zA-Z0-9 ]$/gm
Consider using filter_var()
http://php.net/manual/en/function.filter-var.php
function addressFilter($address)
{
$invalidChars = ['%', '&']; // Array of invalid characters
foreach ($invalidChars as $invalidChar) {
if (strpos($address, $invalidChar) !== false) {
return false;
}
}
return $address;
}
$address = filter_var($_POST['address'], FILTER_CALLBACK, ['options' => 'addressFilter']);