Numeric check

Results 1 to 2 of 2

Thread: Numeric check

  1. #1
    Join Date
    Dec 1969

    Default Numeric check

    Hi All,<BR><BR>Sorry bout this question This is java script realated.<BR>Basically I want to check on a form field only numeric character allowed when form will submit.<BR><BR>Please let me know <BR><BR>Thanks<BR>Affan<BR>

  2. #2
    Join Date
    Dec 1969

    Default paste this code

    //check numeric form fields str=&#062;document.form.controlname,<BR>txtname=&# 062;is the name u want the control to be refered as,ie,"age text box" etc...,flag=&#062;pass "N" or "Y" to this..will check the textbox if "Y" is passed[mandatory field],will not check this field if "N" is passed whether field is left blank or not...<BR><BR>function cknum(str,txtname,flag)<BR>{ <BR> var len;<BR> len=str.value.length-1;<BR> if(flag==&#039;Y&#039;)<BR> {<BR> if(str.value.length==0)<BR> {<BR> alert("Please enter &#039;"+txtname+"&#039;");<BR> str.focus();<BR> return false;<BR> }<BR> } <BR><BR> for(i=0;i&#060;=len;i++) <BR> {<BR> if((str.value.charAt(i)&#060;"0" &#124&#124 str.value.charAt(i)&#062;"9")) <BR> {<BR> alert("Enter only numbers in &#039;"+txtname+"&#039;");<BR> str.value="";<BR> str.focus();<BR> return false;<BR> }<BR> }<BR> return true;<BR>}<BR><BR>i am logging off, will be there tomorrow, any queries just mail to

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts