Web Analytics Made Easy -
StatCounter Need Form to Validate Phone Number Only - CodingForum

Announcement

Collapse
No announcement yet.

Need Form to Validate Phone Number Only

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    Searching just within this forum

    Comment


    • #3
      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.
      Having said that, I've probably told you more than I know.

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎