lilywong Posted March 30, 2006 Share Posted March 30, 2006 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 More sharing options...
GBS Posted April 19, 2006 Share Posted April 19, 2006 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 https://forums.phpfreaks.com/topic/6142-javascript-form-validation-problem/#findComment-28782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.