JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 22nd, 2006, 10:06 PM
imparator imparator is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 14 imparator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 25 m 34 sec
Reputation Power: 0
Need help validating Australian phone numbers

Hi guys, I'm having some trouble validating Australian phone numbers (both land line and Mobile)

I'm using to following reg expression which i got from:http://regexlib.com/REDetails.aspx?regexp_id=1248

Code:
^[0-9]{10}$|^\(0[1-9]{1}\)[0-9]{8}$|^[0-9]{8}$|^[0-9]{4}[ ][0-9]{3}[ ][0-9]{3}$|^\(0[1-9]{1}\)[ ][0-9]{4}[ ][0-9]{4}$|^[0-9]{4}[ ][0-9]{4}$


But when I open the JavaScript Console in Firefox i get:

Error: syntax error
Line: 31, Column: 56

As I'm using an external file i've posted the contents below:

Code:
function validate_form ( )
{
	valid = true;
	

        	if ( document.contact.first_name.value == "" )
        	{
                alert ( "Please fill in the 'First Name' box." );
                valid = false;
        	}
			
			if ( document.contact.sur_name.value == "" )
        	{
                alert ( "Please fill in the 'Surname' box." );
                valid = false;
        	}

			if ( document.contact.address.value == "" )
        	{
                alert ( "Please fill in the 'Address' box." );
                valid = false;
        	}

			if ( document.contact.phone_number.value == "" )
        	{
                alert ( "Please fill in the 'Phone Number' box." );
                valid = false;
        	}

			
			else if ( document.contact.phone_number.value.search(^[0-9]{10}$|^\(0[1-9]{1}\)[0-9]{8}$|^[0-9]{8}$|^[0-9]{4}[ ][0-9]{3}[ ][0-9]{3}$|^\(0[1-9]{1}\)[ ][0-9]{4}[ ][0-9]{4}$|^[0-9]{4}[ ][0-9]{4}$) ==-1)
        	{
                alert ( "Phone Number is in an invalid format." );
                valid = false;
        	}

			
			if ( document.contact.email.value == "" )
        	{
                alert ( "Please fill in the 'Email' box." );
                valid = false;
        	}
			
			
			else if ( document.contact.email.value.search(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) ==-1)
        	{
                alert ( "Email is in an invalid format." );
                valid = false;
        	}




return valid; 
}


I'm new to JavaScript so any help you provide would be much appreciated

Thankyou in advance.

Reply With Quote
  #2  
Old August 5th, 2006, 08:31 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 473 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 19 m 14 sec
Reputation Power: 3
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
what do your phone #'s look like??

Reply With Quote
  #3  
Old August 6th, 2006, 03:25 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 996 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 875113 Folding Title: Super Ultimate Folder - Level 2Folding Points: 875113 Folding Title: Super Ultimate Folder - Level 2Folding Points: 875113 Folding Title: Super Ultimate Folder - Level 2Folding Points: 875113 Folding Title: Super Ultimate Folder - Level 2Folding Points: 875113 Folding Title: Super Ultimate Folder - Level 2Folding Points: 875113 Folding Title: Super Ultimate Folder - Level 2Folding Points: 875113 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 11 m 36 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
You need to enclose your regular expressions in quotes, so replace
Code:
^[0-9]{10}$|^\(0[1-9]{1}\)[0-9]{8}$|^[0-9]{8}$|^[0-9]{4}[ ][0-9]{3}[ ][0-9]{3}$|^\(0[1-9]{1}\)[ ][0-9]{4}[ ][0-9]{4}$|^[0-9]{4}[ ][0-9]{4}$
with
Code:
"^[0-9]{10}$|^\(0[1-9]{1}\)[0-9]{8}$|^[0-9]{8}$|^[0-9]{4}[ ][0-9]{3}[ ][0-9]{3}$|^\(0[1-9]{1}\)[ ][0-9]{4}[ ][0-9]{4}$|^[0-9]{4}[ ][0-9]{4}$"



and
Code:
/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
with
Code:
"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
.
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 278

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Need help validating Australian phone numbers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT