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
https://forums.phpfreaks.com/topic/6142-javascript-form-validation-problem/
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,,



Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.