1

I have a form in which I want to disable the submit button if there are any characters other than A-Z, a-z, and 0-9.


What I have now is...

    <form name=form action=process.cgi method=POST />
    <input type=text name=field1 />
    <input type=password name=field2 />
    <input type=submit value=submit />
    </form>

I am trying to make it so that the details are not submitted untill field1 and field2 only have A-Z, a-z, and 0-9

4

3 回答 3

1
<input type="text" id="name">
<input type="button" id="but" onClick="validate()" Value="Submit">

还有你的js

String.prototype.isValid = function(){return /^\w*$/.test(this);}

    function validate() {
    if(document.getElementById('name').value.isValid()){
        alert('valid')   ;             

    } else{
        alert('Invalid')   ;     
    }    
        }

检查这个演示

更新以包括表单提交更新的演示

第二次更新在这里

于 2012-09-11T04:42:38.953 回答
0

Use javascript / JQuery / Server side, to validate text and password with the mentioned regex

[A-Za-z\d]+
于 2012-09-11T04:33:26.690 回答
0

there is a lot to this question.

I would recommend

1) javascript regex 2) Jquery

You will use regex to ensure that there are not any spaces etc. And jquery to disable the button.

于 2012-09-11T04:34:55.817 回答