Yesterday, I just finished my web program application on GAD Toyota website. It was called travel settlement reminder system. This application can remind user who have arrived from overseas travelling to settle the travel document. Reminder system works using email forwarding that can run automaticaly base on schedule.
In final review, there some new requirement that on field ammount must can’t enter with text. So I must create script to validate the numeric field that user can’t enter with text ones.
After searching on the internet and create some question to uncle google, there are some script to solve this problem. Here this script:
Note: name of field is “pnum” and name of form is “chechknum”
/* start*/
<script language=”JavaScript1.2″>
function checknumber(){
var x=document.checknum.pnum.value
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
alert(“Please input a valid number!”)
testresult=false
}
return (testresult)
}
</script>
<script>
function checkban(){
if (document.layers||document.all||document.getElementById)
return checknumber()
else
return true
}
</script>
/*end*/
/**this script on GAD website */
<script language=”javascript”>
addCalendar(“Calendar1″, “Select Date of Return”, “strdatertn”, “frmexp”);
addCalendar(“Calendar3″, “Select Date of Leaving”, “strdtleaving”, “frmexp”);
setWidth(90, 1, 15, 1);
setColor(“#151573″, “#bbcded”, “#ffffff”, “#ffffff”, “#333333″, “#151573″, “#333333″);
setFontColor(“#ffffff”, “#000000″, “#333333″, “#ffffff”, “#ffffff”);
setFormat(“dd/mm/yyyy”);
function Validate_frm() {
with(document.frmexp) {
if(strexpname.value == “”) {
alert(“Please enter Name !!”);
strexpname.focus();
return false;
}
if(strexpno.value == “”) {
alert(“Please enter Noreg !!”);
strexpno.focus();
return false;
}
if(strdatertn.value == “”) {
alert(“Please enter Date of Return !!”);
strdatertn.focus();
return false;
}
var x=document.frmexp.strmon1.value;
var anum=/(^\d+$)|(^\d+\’\d+$)/;
if (anum.test(x)){
}else{
alert(“Please input Preparation allowance with a numeric !”);
strmon1.focus();
return false;
}
var x=document.frmexp.strmon2.value;
var anum=/(^\d+$)|(^\d+\’\d+$)/;
if (anum.test(x)){
}else{
alert(“Please input Winter allowance with a numeric !”);
strmon2.focus();
return false;
}
var x=document.frmexp.strmon3.value;
var anum=/(^\d+$)|(^\d+\’\d+$)/;
if (anum.test(x)){
}else{
alert(“Please input Meal allowance with a numeric !”);
strmon3.focus();
return false;
}
var x=document.frmexp.strmon4.value;
var anum=/(^\d+$)|(^\d+\’\d+$)/;
if (anum.test(x)){
}else{
alert(“Please input Hotel allowance with a numeric !”);
strmon4.focus();
return false;
}
var x=document.frmexp.strmon5.value;
var anum=/(^\d+$)|(^\d+\’\d+$)/;
if (anum.test(x)){
}else{
alert(“Please input Miscellaneous allowance with a numeric !”);
strmon5.focus();
return false;
}
var x=document.frmexp.strmon6.value;
var anum=/(^\d+$)|(^\d+\’\d+$)/;
if (anum.test(x)){
}else{
alert(“Please input Fiscal/Taxes with a numeric !”);
strmon6.focus();
return false;
}
if( confirm(“You will redirect to confirmation page !”) ) {
submit();
}
}
return true;
}
</script>
/****END***/
Java script can also validate on email, date, max/min lenght of data input on form. I think javascript language is good to check the content of form box that can inform user before they submit the data.
>>aris<<
First post at Sunday, November 5, 2006, 09:08 AM