Jump to content


Photo

Javascript Form Validation Problem


  • Please log in to reply
1 reply to this topic

#1 lilywong

lilywong
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 30 March 2006 - 02:34 AM

I want to check a particular phone number prefix with 6,
for example, each phone number should start with 60123456789, rather than 0123456789, how to do that ?
the following is the other phone number codes.

=================================================
<script language="javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(txtFName,"Member Full Name must be filled out!")==false)
{txtFName.focus();return false}

if (validate_required(txtName,"Card Name must be filled out!")==false)
{txtName.focus();return false}

if (validate_required(txtHP,"Handphone number must be filled out!")==false)
{txtHP.focus();return false}
}
}

</script>


#2 GBS

GBS
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 19 April 2006 - 10:53 PM

Hi there,

Still if I get it,... (brrrrr,, my english,,,) this kind of code could maybe help you,,
<html>
<script>
function DoTheJob(){
var numbers = document.getElementById('testing').value;

if (numbers == "")
    {
    return;
    }

var num_parts = numbers.split("6");
if (num_parts[0].length > 0)
    {
    error_report();
    return;
    }
alert("Yep,, we have the number 6 in 1st position,... :)");
}

function error_report(){
alert ("Invalid numbers. Please try again.");
document.getElementById('testing').value = "";
document.getElementById('testing').focus();
return;

}
</script>

<body>

Try some numbers there: <input type="text" id="testing" value="" onchange="DoTheJob(this)">

<script>
document.getElementById('testing').value="";
document.getElementById('testing').focus();
</script>

</body>
</html>

Good luck & hoping it helps,

l8tr,,




Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users