Mobile Phone Number Validation!!!!!

Results 1 to 5 of 5

Thread: Mobile Phone Number Validation!!!!!

  1. #1
    Join Date
    Dec 1969
    Posts
    5

    Default Mobile Phone Number Validation!!!!!

    I&#039;m trying to validate a mobile phone number on my registration but I&#039;m only concerned with validating the number if the person registering is from Ireland.<BR>When I use the followong code, the validation works but the country selected (ie.Ireland) doesn&#039;t get saved in the database.<BR><BR>if(form.cboParentLocation.selecte dIndex = &#039;564&#039;) <BR> { <BR> var mobilePattern = new RegExp("(^35386&#124 35387&#124 35385) *[0-9$]{7}"); <BR> if (!mobilePattern.test(form.txtMobileNumber.value) && form.txtMobileNumber.value.length&#062;0)<BR> {<BR> alert(&#039;Your mobile number does not look valid.
    Please enter it in the form: (country code) + (mobile number) - (initial zero)
    eg. for Ireland: "353861234567"&#039;);<BR> form.txtMobileNumber.focus(); <BR> return(false); <BR> } <BR> } <BR><BR>However if I use a double "equals" sign instead of a single one on the first line, the country is saved but the validation doesn&#039;t work!<BR><BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    312

    Default RE: Mobile Phone Number Validation!!!!!

    Let&#039;s review your script:<BR><BR>if(form.cboParentLocation.selectedI ndex=&#039;564&#039;)<BR><BR>::WHOA::<BR><BR>&#039 ;=&#039; is an ASSIGMENT operator. You CANNOT use it like that here. &#039;=&#039; will assign &#039;564&#039; to the selectedIndex, which is obviously not desirable.<BR><BR>You *MUST* use &#039;==&#039; (equals or is equal to). The opposite is &#039;!=&#039;.<BR><BR>You didn&#039;t say if you were getting an error or not, but I don&#039;t like to use of "form.whateverfield.value". Is &#039;form&#039; the name of your form?<BR><BR>I always use something like:<BR>document.forms[0].frmField.value.<BR><BR>Or, more accurately, and cleaner:<BR><BR>with(document.forms[0])<BR>{<BR>code goes here<BR>}<BR><BR>etc.<BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    5

    Default RE: Mobile Phone Number Validation!!!!!

    Thank You for your help!...I am new to this as I&#039;m sure you have gathered!<BR><BR>Yes &#039;form&#039; is the name of my form in this case. I wasn&#039;t getting any error message, it just didn&#039;t validate properly.<BR><BR>I&#039;m not too sure about what you meant in your reply.....<BR><BR>should my code read:<BR><BR>with(document.form["564"])<BR> { <BR> var mobilePattern = new RegExp("(^35386&#124 35387&#124 35385) *[0-9$]{7}"); <BR> if (!mobilePattern.test(form.txtMobileNumber.value) && form.txtMobileNumber.value.length&#062;0)<BR> {<BR> alert(&#039;Your mobile number does not look valid.
    Please enter it in the form: (country code) + (mobile number) - (initial zero)
    eg. for Ireland: "353861234567"&#039;);<BR> form.txtMobileNumber.focus(); <BR> return(false); <BR> } <BR> } <BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    312

    Default RE: Mobile Phone Number Validation!!!!!

    &#039;form&#039; is probably a reserved word. I&#039;d ditch it.<BR><BR>&#039;document&#039; is the top level of your object. It refers to the entire HTML page.<BR><BR>&#039;forms[0]&#039; is a reference to your form in the &#039;document&#039;. It&#039;s an array reference and &#039;0&#039; is the first form. If you had two forms on your page, forms[0] would be the first, forms[1] would be the second form.<BR><BR>You would *not* use &#039;564&#039;, because that would be trying to reference form object 565. Yes?<BR><BR>Now, you can use a form name there instead = it&#039;s case sensitive - but stay away from reserved words. Try:<BR><BR>&#060;form name="myForm" ... ... ... &#062;<BR><BR>And then:<BR><BR>document.myForm<BR><BR>Now, the next part is the next level down. We&#039;ve gone from document to form to ... form elements. This is the bit you are trying to validate. Therefore:<BR><BR>&#039;document.myForm.phonenumbe r&#039; would access a form element called &#039;phonenumber&#039;. This is case sensitive also, so be wary.<BR><BR>Now, this is fine and dandy, but what part of the &#039;phonenumber&#039; object are you trying to reference? That&#039;s right ... it&#039;s value.<BR><BR>document.myForm.phonenumber.value<BR ><BR>OR<BR><BR>document.forms[0].elements["phonenumber"].value<BR><BR>Or, if youe phonenumber was the 3rd element on the page (and I never do this myself):<BR><BR>document.forms[0].elements[2].value (the arrays start at zero). That way is confusing.<BR><BR>Get rid of the &#039;form&#039; name and see how that goes .. but you understand the rest of it, right?


  5. #5
    Join Date
    Dec 1969
    Posts
    5

    Default RE: Mobile Phone Number Validation!!!!!

    Thank you very much!<BR><BR>That works fine now........ but only in Internet Explorer!!<BR>The ".value" attribute does not seem to be recognised in Netscape..........or could it be something else?<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •