DOJEUN's Notepad
 LISTへ 

【Javascript】テキストボックスにアルファベットのみ入力許可する方法

テキストボックスにアルファベットのみ入力許可する方法 任意のテキストボックスにアルファベットのみ受け入れるようにするサンプルです。


<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta http-equiv="Content-Language" content="ja">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title></title>
<script type="text/javascript">
<!--
function fncTEST(){
	var str = frm1.txtA.value;
	
	if(ChkAlp(str)){
		alert("OK");
	}else{
		alert("アルファベット以外が含まれています。");
	}
}
function ChkAlp(str){
	var stralp=str.match(/[^a-z]/gi);
	if(stralp){
		return false;
	}
	return true;
}
//-->
</script>
</head>
<body>
<form name="frm1">
<input type="text" name="txtA" size="10" maxlength="10" /><br />
<input type="button" value="CHECK" onclick="fncTEST()" />
</form>
</body>
</html>