|
 |
|
ช่วยหน่อยนะคะ อยากได้โค้ด JavaScript ที่ให้กรอกเฉพาะตัวเลข (Number) 10 ตัวเท่านั้น |
|
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>Ajax form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function NumberOnly(str,obj){
var orgi_text="1234567890";
var str_length=str.length;
var str_length_end=str_length-1;
var isNUmber=true;
var Char_At="";
for(i=0;i<str_length;i++){
Char_At=str.charAt(i);
if(orgi_text.indexOf(Char_At)==-1){
isNUmber=false;
}
}
if(str_length>=1){
if(isNUmber==false){
obj.value=str.replace(/[^0-9]/g, '');
}
}
return isNUmber;
}
function ThaiOnly(str,obj){
var orgi_text="ๅภถุึคตจขชๆไำพะัีรนยบลฃฟหกดเ้่าสวงผปแอิืทมใฝ๑๒๓๔ู฿๕๖๗๘๙๐ฎฑธํ๊ณฯญฐฅฤฆฏโฌ็๋ษศซฉฮฺ์ฒฬฦ ";
var str_length=str.length;
var str_length_end=str_length-1;
var isThai=true;
var Char_At="";
for(i=0;i<str_length;i++){
Char_At=str.charAt(i);
if(orgi_text.indexOf(Char_At)==-1){
isThai=false;
}
}
if(str_length>=1){
if(isThai==false){
obj.value=str.substr(0,str_length_end);
}
}
return isThai;
}
function EngOnly(str,obj){
var orgi_text="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var str_length=str.length;
var str_length_end=str_length-1;
var isEng=true;
var Char_At="";
for(i=0;i<str_length;i++){
Char_At=str.charAt(i);
if(orgi_text.indexOf(Char_At)==-1){
isEng=false;
}
}
if(str_length>=1){
if(isEng==false){
obj.value=str.substr(0,str_length_end);
}
}
return isEng;
}
</script>
</head>
<body>
<p>
<label for="NUM">ตัวเลข</label>
<input type="text" name="NUM" id="NUM" onKeyUp="NumberOnly(this.value,this)">
</p>
<p>
<label for="THAI">ไทย</label>
<input type="text" name="THAI" id="THAI" onKeyUp="ThaiOnly(this.value,this)">
</p>
<p>
<label for="ENG">อังกฤษ</label>
<input type="text" name="ENG" id="ENG" onKeyUp="EngOnly(this.value,this)">
</p>
<p> </p>
</body>
</html>
|
 |
 |
 |
 |
Date :
2013-01-02 21:38:10 |
By :
Krungsri |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แจ่มครับ
|
 |
 |
 |
 |
Date :
2013-01-03 05:58:58 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|