javascript 全角轉換實現(xiàn)代碼
更新時間:2009年07月17日 00:58:24 作者:
當客戶端用戶切換輸入法至全角時可能您的表單提交會有漏洞哦!不過事實上js有這功能 可以將其轉換為非全角字符!
下面我們來看下這個例子吧!
<html>
<head>
<title>jqueryDemo:quanjiaoNum</title>
<script src="jquery.js" src="jquery.js" type="text/javascript"></script>
<script type="text/javascript"><!--
function changeNum(){
var qjNum=$("input[@name=qjNum]").val();
var toAscii=qjNum.charCodeAt();
if(toAscii > 65295 && toAscii < 65306 && qjNum.length == 11)
{
var toBack = 0;
var temp = 0;
var unite = "";
for(var i=0;i < qjNum.length;i++)
{
toAscii=qjNum.charCodeAt(i);
toBack =toAscii-65248;
temp = String.fromCharCode(toBack);
unite = unite + temp ;
}
alert(unite);
return true;
}
if(toAscii > 47 && toAscii < 58 && qjNum.length == 11)
{
alert(qjNum);
return true;
}
else{
alert("請輸入正確的手機號碼");
document.myform.qjNum.value="";
return false;
}
}
// --></script>
</head>
<form name="myform" action="">
中文數(shù)字轉換成阿拉伯數(shù)字:<input type="text" id="qjNum" name="qjNum"/><input type="button" value="提 交" onclick="changeNum()"/>
</form>
</html>
這是個判斷手機號的問題!另外請注意我這還用到了jquery!記得引入哦……
復制代碼 代碼如下:
<html>
<head>
<title>jqueryDemo:quanjiaoNum</title>
<script src="jquery.js" src="jquery.js" type="text/javascript"></script>
<script type="text/javascript"><!--
function changeNum(){
var qjNum=$("input[@name=qjNum]").val();
var toAscii=qjNum.charCodeAt();
if(toAscii > 65295 && toAscii < 65306 && qjNum.length == 11)
{
var toBack = 0;
var temp = 0;
var unite = "";
for(var i=0;i < qjNum.length;i++)
{
toAscii=qjNum.charCodeAt(i);
toBack =toAscii-65248;
temp = String.fromCharCode(toBack);
unite = unite + temp ;
}
alert(unite);
return true;
}
if(toAscii > 47 && toAscii < 58 && qjNum.length == 11)
{
alert(qjNum);
return true;
}
else{
alert("請輸入正確的手機號碼");
document.myform.qjNum.value="";
return false;
}
}
// --></script>
</head>
<form name="myform" action="">
中文數(shù)字轉換成阿拉伯數(shù)字:<input type="text" id="qjNum" name="qjNum"/><input type="button" value="提 交" onclick="changeNum()"/>
</form>
</html>
這是個判斷手機號的問題!另外請注意我這還用到了jquery!記得引入哦……
相關文章
jQuery EasyUI NumberBox(數(shù)字框)的用法
jQuery EasyUI 數(shù)字框(NumberBox)用法2010-07-07
Jquery通過Ajax訪問XML數(shù)據(jù)的小例子
這篇文章主要介紹了Jquery通過Ajax訪問XML數(shù)據(jù),有需要的朋友可以參考一下2013-11-11

