-
-
Save shane-reaume/4004929 to your computer and use it in GitHub Desktop.
function phonenumber($value) | |
{ | |
$areacode = '[2-9]{1}\d{1}\d{1}'; // You might want to specify '2\d\d' (200 to 299) | |
$prefix = '[2-9]{1}\d{1}\d{1}'; | |
$regex = '#^(\('.$areacode.'\)|'.$areacode.')[\s\.-]?'.$prefix.'[\.-]?\d{4}$#'; | |
if (preg_match($regex, $value)) | |
{ | |
// Number now is in a suitable format | |
// extract digits -- remove this section to not test repeated pattern | |
$digits = preg_replace('#[^\d]+#', '', $value); | |
// All numbers equal are rejected | |
if (preg_match('#^(\d)\1{9}$#', $digits)) | |
return false; | |
// end of pattern check | |
// Otherwise it is accepted | |
return true; | |
} | |
return false; // Not in a recognized format | |
} |
Path is typically site\components\com_rsform\helpers\validation.php
Also, can add CSS...
text-transform: uppercase;
JavaScript...
function toUpCase()
{
document.getElementById("first").value=document.getElementById("first").value.toUpperCase();
document.getElementById("last").value=document.getElementById("last").value.toUpperCase();
document.getElementById("email").value=document.getElementById("email").value.toUpperCase();
}
To filter phone input more on mask, in the <script src="/media/system/js/jquery.maskedinput-1.3.js" type="text/javascript"></script> file, you can append to the mask 2:"[2-9]"
...then change the jQuery to $('#phone').mask('(299)299-9999');
This will limit the start of the prefix and leading number to slow random number inputs.
This is an update to RSFormPro phone validation to be specific to US phone numbers only. I use this as Server-Side validation, along with jQuery validation and a phone mask so user can only input (2xx)2xx-xxxx