Solved

validation field for ic and telephone

Posted on 2001-08-31
3
1,041 Views
Last Modified: 2006-11-17
hai, i need javascript solution in validation fields

1.
<INPUT type="text" NAME="ic1" SIZE="6">-<INPUT type="text" NAME="ic2" SIZE="2">-
<INPUT type="text" NAME="ic3" SIZE="4">

the format is like this:
800101-10-5555

ic1 must be 6 digits, ic2 is from 01 to 13(2 digits) , ic3 must also be 4 digits.

2.
also for telephone validation:
<INPUT TYPE="Text" NAME="phone1" SIZE="3">-<INPUT TYPE="Text" NAME="phone2" SIZE="7">
the format is 089-123456 or 010-1234567
0
Comment
Question by:J2J
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:psogaa
ID: 6444604
Something like this?( added "maxlength" properties in the input boxes for convenience ).

<html>
<head>
<script language=javascript>
function validateForm( myForm ){
  var ic1Reg = /^\d{6}$/;
  var ic2Reg = /^\d{2}$/;
  var ic3Reg = /^\d{4}$/;
  if( !ic1Reg.test( myForm.ic1.value ) || !ic2Reg.test(myForm.ic2.value) || !ic3Reg.test(myForm.ic3.value)){    
    alert('Incorrect ic format');
    return false;
  }
  else if( myForm.ic2.value > 13 ){
    alert('Ic2 value must be less than 14');
    return false;
  }
  return true;
}
</script>
</head>
<body>
<form onsubmit="return validateForm(this);">
<INPUT type="text" NAME="ic1" SIZE="6" maxlength=6>-<INPUT type="text" NAME="ic2" SIZE="2" maxlength=2>-
<INPUT type="text" NAME="ic3" SIZE="4" maxlength=4><br><br>
<input type=submit value=submit>
</form>
</body>

0
 
LVL 2

Accepted Solution

by:
psogaa earned 30 total points
ID: 6444623
oops, missed the phone thing.
Here goes :)

<html>
<head>
<script language=javascript>
function validateForm( myForm ){
  var ic1Reg = /^\d{6}$/;
  var ic2Reg = /^\d{2}$/;
  var ic3Reg = /^\d{4}$/;
  var phone1Reg = /^\d{3}$/;
  var phone2Reg = /^\d{6,7}$/;
  if( !ic1Reg.test( myForm.ic1.value ) || !ic2Reg.test(myForm.ic2.value) || !ic3Reg.test(myForm.ic3.value)){    
    alert('Incorrect ic format');
    return false;
  }
  else if( myForm.ic2.value > 13 ){
    alert('Ic2 value must be less than 14');
    return false;
  }
  if( !phone1Reg.test(myForm.phone1.value) || !phone2Reg.test(myForm.phone2.value) ){
    alert('Incorrect phone format');
    return false;
  }
  return true;
}
</script>
</head>
<body>
<form onsubmit="return validateForm(this);">
<INPUT type="text" NAME="ic1" SIZE="6" maxlength=6>-<INPUT type="text" NAME="ic2" SIZE="2" maxlength=2>-
<INPUT type="text" NAME="ic3" SIZE="4" maxlength=4><br>
<INPUT TYPE="Text" NAME="phone1" SIZE="3" maxlength=3>-<INPUT TYPE="Text" NAME="phone2" SIZE="7" maxlength=7><br><br>
<input type=submit value=submit>
</form>
</body>
0
 

Author Comment

by:J2J
ID: 6470269
thanks for the solution. bye.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Table style position to the left 8 37
Check input text, Number 7 54
Need help for active menu class depending of the page 4 26
Jquery syntax 12 26
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question