代码如何编写?
---------------------------------------------------------------
那要看你的具体要求是什么了
比如输入不能有空
1<script language="javascript">
2function String.prototype.Trim() {return this.replace(/(^\s*) ¦(\s*$)/g,"");}
3function check(f1) {
4if (f1.username.value.Trim()=="")
5{
6alert("用户名不能为空");
7return false;
8}
9}
10</script>
1<form action="" method="post" onsubmit="return check(this)">
2<input name="username" type="text"/>
3</form>
---------------------------------------------------------------
1<script>
2function check(frm){
3if(!frm.username.value.replace(/\s/g,'')){
4alert("用户名不能为空")
5return false
6}
7return true
8}
9</script>
1<form action="" method="post" onsubmit="return check(this)">
2<input name="username" type="text"/>
3</form>
---------------------------------------------------------------
1<script language="javascript">
2function checkdata()
3{
4if ( document.regform.username.value.length < 2 )
5{
6alert("\帐户名的长度不得少于位!!!");
7document.regform.username.focus();
8return false;
9}
10if ( nameformat(document.regform.username.value) == false)
11{
12alert("\帐户名只允许由英文、数字或下划线组成,不能含有空格或其它字符!!!");
13document.regform.f_username.focus();
14}
15............
16............
17自己发挥吧!
18</script>