Jump to content

Javascript Form Validation Problem


lilywong

Recommended Posts

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>
Link to comment
Share on other sites

  • 3 weeks later...
Hi there,

Still if I get it,... (brrrrr,, my english,,,) this kind of code could maybe help you,,
[code]
<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>
[/code]

Good luck & hoping it helps,

l8tr,,



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.