正则表达式:/^[a-zA-Z]$/;(以字母开头字母结束)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <script type="text/javascript" src="./js/jquery-1.7.2.min.js"></script> <script type="text/javascript">$(document).ready(function(){ $("#input").change(function(){var value=$("#input").val()var reg = /^[a-zA-Z]$/;if(reg.test(value) === false){alert("只能输入字母,请重新输入"); return false}});}); </script> <body> <input id="input" type="text" placeholder="请输入,,,,,"/></body> </html>