I need a good validation for tild(~) and tilt(`) character in PHP and Jquery. Here is the Jquery validation what i have made.
$.validator.addMethod("validSMS", function(value, element) {
if (value.indexOf('~') === -1 || value.indexOf('`') === -1)
{
return true;
}
else
{
return false;
}
}, "Tild and tilt Character is not allowed");
But I need another good method for this validation in Jquery and in PHP also.
This is the php version, using strpos
if (strrpos($mystring, "~") === false && strrpos($mystring, "`") === false ) {
// $mystring has no tild(~) and tilt(`) chars
}
this is what can be done with javascript. you can change condition as per your requirement.
<script language=javascript>
var txt='jayd~ev';
var re1='.*?'; // Non-greedy match on filler
var re2='(~)'; // Any Single Character 1
var p = new RegExp(re1+re2,["i"]);
var m = p.exec(txt);
if (m != null)
{
var c1=m[1];
document.write("("+c1.replace(/</,"<")+")"+"
");
}
</script>