Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Need Form to Validate Phone Number Only

    This is what I have so far, it is a template I copied from my working E-mail validation. I'm assuming I have to make it so it's just an array of numbers but I really don't know Java too well.

    Essentially I just want numbers only to be accepted into the phone field.

    Code:
    else if(fieldType == 'phone')
    				{	
    					if((required == 1 && fieldObj.value=='')  ||  (fieldObj.value!=''  && !validate_phone(fieldObj.value)))
    					{				
    						fieldObj.setAttribute("class","mainFormError");
    						fieldObj.setAttribute("className","mainFormError");
    						fieldObj.focus();
    						return false;					
    					}
    
    				}
    
    
    
    				function validate_phone(phoneStr)
    			{		
    				apos=phoneStr.indexOf("@");
    				
    
    				if (apos<1||dotpos-apos<2) 
    				{
    					return false;
    				}
    				else
    				{
    					return true;
    				}
    			}

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    617
    Thanks
    1
    Thanked 20 Times in 20 Posts
    I wrote a function to check every phone number variation I could find. Just within the North American Numbering Plan, there are over 40 possibilities, and then multiple sub-formats. PM me if you'd like a copy of it.


  •  

    Posting Permissions

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