如何只允许表单文本字段中的阿拉伯字符,我尝试使用此代码,但它不使用keyup工作的keypress但它不使用keyup它是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Character Filtering</title>
<script type="text/javascript">
function CheckEnglishOnly(field)
{
var sNewVal = "";
var sFieldVal = field.value;
for(var i = 0; i < sFieldVal.length; i++) {
var ch = sFieldVal.charAt(i);
var c = ch.charCodeAt(0);
if(c < 0 || c > 255) {
// Discard
}
else {
sNewVal += ch;
}
}
field.value = sNewVal;
}
function CheckArabicOnly(field)
{
var sNewVal = "";
var sFieldVal = field.value;
for(var i = 0; i < sFieldVal.length; i++) {
var ch = sFieldVal.charAt(i);
var c = ch.charCodeAt(0);
if(c < 1536 || c > 1791) {
// Discard
}
else {
sNewVal += ch;
$( "#txtArabic" ).focus();
}
}
field.value = sNewVal;
}
</script>
</head>
<body>
Arabic Only (onchange): <input type="text" id="txtArabic" if(onkeyup) { onkeyup="CheckArabicOnly(this);" } elseif(onpaste) { onkeyup="CheckArabicOnly(this);" }/><br />
</body>
</html>
任何人都会非常感激