Current location: Hot Scripts Forums » General Web Coding » JavaScript » I need Help validating Australian Phone numbers


I need Help validating Australian Phone numbers

Reply
  #1 (permalink)  
Old 07-22-06, 02:59 AM
imparator imparator is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
I 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 (permalink)  
Old 07-24-06, 11:08 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
You must put // around the RegExp or JS will try to interpret it as a variable or number.
Code:
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)
You can also remove the
Code:
			if ( document.contact.phone_number.value == "" )
        	{
                alert ( "Please fill in the 'Phone Number' box." );
                valid = false;
        	}

			
			else
part above it since the RegExp will not match if the string is empty, so the previous test is unneccessary.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #3 (permalink)  
Old 07-25-06, 07:20 AM
imparator imparator is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
that fixed it, thank you very much
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hassle FREE and Rock Solid Hosting *24/7 Live Phone Support* vortech General Advertisements 0 08-26-05 10:14 AM
Mobile Phone Cart !!!!!!!!!!!! shamend143 Script Requests 0 02-16-05 04:19 PM
Cheap International Phone Card & Domestic Calling Card with cheap rates & Price pthq General Advertisements 0 09-27-04 09:15 PM
Need script writer for cell phone ringtones/screensavers/games upload site hostdeez Job Offers & Assistance 2 03-28-04 04:54 PM
camera phone image poster apt2 Script Requests 2 08-29-03 07:20 PM


All times are GMT -5. The time now is 11:14 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.