2014-02-26 44 views

回答

0
function validate() { 
    //Make a selector pointing to your input first 
    var myInput = document.getElementById('yourInputId').value 

    //Validate length: 
    if (myInput.length >= 8) { 
    //Check for age 
    if (eval(myInput) >= 16) { 
    alert('your input is ok!'); 

    } 
    else { 
    alert('Minimum age is 16!'); 
    } 
    } 
    else { 
    alert('input too short!'); 
    } 
} 

PS圖標的排除:對於字符排除你應該跳進Regular Expressions

(例如噸在網絡上,只是谷歌吧!)

+0

請注意,W3C是不一樣的W3Schools - 兩個[根本不相關](http://www.w3fools.com/)。 –