Is Valid Date

by Javascript Specialist August 22, 2014 00:14
A couple of things to note when validating date using Javascript:
1. Month begins with 0 to 11. So January=0, February=1, March=2 etc. 2014-01-05 means 2014-Feb-05
2. 2014-02-32 is a valid date according to Javascript. The javascript date object will automatically convert it to 2014-03-01
 
function IsDate(event) {
var chCode = ('charCode' in event) ? event.charCode : event.keyCode;
if (chCode >= 48 && chCode <= 57) {
return true;
}
else if (chCode == 189) {
var s = obj.value.split('-');
if (s.length>2) {
alert('Too many dashes. Only numbers or two dashes.');
return false;
}
return true;
}
else {
alert('Numbers only and dashes only');
return false;
}
}
...
<input type='text' onkeypress='return IsDate(event)' />

Input Validation | JavaScript | References

What is the best font type to use for coding

by Web Designer August 6, 2014 21:28
.code
{ font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New; }

CSS - Cascading Stylesheets | References

How to Input only Decimal

by Javascript Specialist August 6, 2014 00:13
<script>
function IsDecimal(event,obj) {
    var chCode = ('charCode' in event) ? event.charCode : event.keyCode;    
    if (chCode >= 48 && chCode <= 57)        {        
        return true;    
    } else if  (chCode==46) {
        if (obj.value.indexOf('.')>=0) {
                alert('Too many decimals. Only numbers or one decimal.');
                return false;
            }
            return true;
        }    else    {
                alert('Only numbers or one decimal');
        return false;    }}
</script>
<input onkeypress="return IsDecimal(event,this)" type="text">

How Tos | Input Validation | JavaScript

How to input only Integers

by Javascript Specialist August 6, 2014 00:20
function IsInt(event) {
    var chCode = ('charCode' in event) ? event.charCode : event.keyCode;
    if (chCode >= 48 && chCode <= 57) {
        return true;
    }
    else {
        alert('Numbers only');
        return false;
    }
}

<input type='text' onkeypress='return IsInt(event)' />

How Tos | Input Validation | JavaScript