Sunday, June 24, 2012

Create table through javascript

Javascript all key validation

function validateNumberKey(event) {
   
    var key = window.event ? event.keyCode : event.which;
    if (event.keyCode == 8 || event.keyCode == 46
     || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 9) {
        return true;
    }
    else if ( key < 48 || key > 57 ) {
        return false;
    }
    else return true;
}

function validateAlphaNumericKey(event) {
    var key = window.event ? event.keyCode : event.which;
    if (event.keyCode == 8 || event.keyCode == 46
     || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 9) {
        return true;
    }
    else if ( key >= 48 && key <= 57 )
    {
        return true;
    }
    else if ( key >= 65 && key <= 90 )
    {
        return true;
    }
    else if ( key >= 97 && key <= 122 )
    {
        return true;
    }
    else return false;
}
function validateAlphabeticKey(event) {
    var key = window.event ? event.keyCode : event.which;
    if (event.keyCode == 8 || event.keyCode == 46
     || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 9) {
        return true;
    }
    else if ( key >= 65 && key <= 90 )
    {
        return true;
    }
    else if ( key >= 97 && key <= 122 )
    {
        return true;
    }
    else return false;
}




Number : <input type="text" name="number" onkeypress="return validateNumberKey(event)"/>
AlphaNumeric : <input type="alphanumaric" name="an" onkeypress="return validateAlphaNumericKey(event)"/>
Alphabetic : <input type="text" name="fname" onkeypress="return validateAlphabeticKey(event)" />

No comments:

Post a Comment

Please mention your comments.......