Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5961
  • Last Modified:

fax number validation

I want to have a validation script for fax number.

1-111-111-1234 is valid number

Would you please help me how i can start?
0
bbvic
Asked:
bbvic
  • 3
  • 2
1 Solution
 
LakioCommented:
<HTML>
<HEAD>
      <TITLE>Lakio Foxy validation script for fax numbers</TITLE>
<script>
function rule(fax){
return /^\d-\d{3}-\d{3}-\d{4}$/.test(fax);
}
</script>
</HEAD>
<BODY>
<a href="#" onclick="alert( rule('1-111-111-1234') )">Test 1-111-111-1234 </a><br>
<a href="#" onclick="alert( rule('11-111-111-12341') )">Test 1-111-111-1234 </a>
</BODY>
</HTML>
0
 
LakioCommented:
<a href="javascript:;" onclick="alert( rule('1-111-111-1234') )">Test 1-111-111-1234 </a><br>
<a href="javascript:;" onclick="alert( rule('1-111-111-12341') )">Test 1-111-111-12341 </a><br>
<a href="javascript:;" onclick="alert( rule(prompt('Please enter your FAX.', '1-111-111-1234')) )">Test anything you like </a><br>
0
 
ZvonkoSystems architectCommented:
Here my proposal:

<html>
<head>
<title>Zvonko &#42;</title>
<script>
function checkForm(theForm){
  if(!theForm.fax.value.match(/^1[\ \-]?\d{3}[\ \-]?\d{3}[\ \-]?\d{4}$/)){
    alert("Please enter the FAX number in this format:\n\t1-999-999-9999");
    theForm.fax.select();
    theForm.fax.focus();
    return false;
  }
  return true;
}
</script>
</head>
<body>
<form onSubmit="return checkForm(this)">
<input type="text" name="fax" size="14" maxlength="14">
<input type="submit">
</form>
</body>
</html>

0
 
LakioCommented:
 why not just focus()?

theForm.fax.select();
theForm.fax.focus();
0
 
ZvonkoSystems architectCommented:
Open your own question and I can explain it to you ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now