[SOLVED] using .match

This is a discussion on "[SOLVED] using .match" within the JavaScript Forum section. This forum, and the thread "[SOLVED] using .match are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 29th, 2007, 11:28
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] using .match

Hi,

Im using the .match command to check to see if the value of a form starts with "+44" and if so raise an alert.

That bit is pretty easy but what I cant get it to do is check that the value starts with "+44" AND THEN check if there are any of the numbers "3, 4, 5, 6, 8, 9, 0".

Here is the code.

Any help would be greatly appreciatted.

Code: Select all
             if (temp.match(/^\+44/ && [3|4|5|6|8|9|0])
             {
             alert("Please enter a valid UK Phone number including area code");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
Reply With Quote

  #2 (permalink)  
Old Oct 29th, 2007, 11:50
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using .match

You can try

if (temp.match(/^(\+44 )([3-6]|[8-9]|0|1){1}/))
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)

Last edited by Rakuli; Oct 29th, 2007 at 12:03. Reason: Fixed typo
Reply With Quote
  #3 (permalink)  
Old Oct 29th, 2007, 12:14
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using .match

for some reason that doesnt seem to work. It doesnt raise the alert if you put in a number such as +443392666666.

Any ideas???

Thanks as usual to Rakuli
Reply With Quote
  #4 (permalink)  
Old Oct 29th, 2007, 12:17
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using .match

hang on... I dont think I explained the situation well enough in the first place.

It needs to check if the number begins with +44 if so, it checks to see if the 4th character is either 3,4,5,6,8,9 and if both are true raise the alert.

Sorry about that rakuli.

Thanks eon.
Reply With Quote
  #5 (permalink)  
Old Oct 29th, 2007, 12:32
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using .match

Okay,

if (temp.match(/^(\+44 )([3-6]{1}|[8-9]{1}|0|1)/))
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #6 (permalink)  
Old Oct 29th, 2007, 12:38
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using .match

still not working... I cant see why??

Here is the full code just incase I have mucked another rule up somewhere....
Code: Select all
<script type="text/javascript">
<!--

function validate_form ( )
{


   document.callmeback_form.telephone.value=filterNum(document.callmeback_form.telephone.value)

   function filterNum(str) {
   re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
   // remove special characters like "$" and "," etc...
   return str.replace(re, "");
    }
    
    if (document.callmeback_form.name.value == "" )
    {
    alert ( "Please enter your name." );
    document.callmeback_form.name.focus();
    document.callmeback_form.name.style.background = '#FF8600';
    document.callmeback_form.name.style.border= "1px solid #A5ACB2";
    document.callmeback_form.name.style.width= "132px";
    document.callmeback_form.name.style.height= "15px";
    return false;
    }

    var temp = document.callmeback_form.telephone.value;

     if (temp=="")
     {
     alert("Please enter a valid UK Phone number including area code");
    document.callmeback_form.telephone.focus();
    document.callmeback_form.telephone.style.background = '#FF8600';
    document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
    document.callmeback_form.telephone.style.width = "132px";
    document.callmeback_form.telephone.style.height = "15px";
    return false;
    }
      
        if (temp.match(/^\+440/) && temp.length ==14)
        {
        document.callmeback_form.telephone.value = temp.replace(/^\+440/, "+44");
        return true;
        }
        if (temp.match(/^\+3530/) && temp.length ==13)
        {
        document.callmeback_form.telephone.value = temp.replace(/^\+3530/, "+353");
        return true;
        }
        if (temp.match(/^00440/) && temp.length ==15)
        {
        document.callmeback_form.telephone.value = temp.replace(/^00440/, "0044");
        return true;
        }
        if (temp.match(/^003530/) && temp.length ==14)
        {
        document.callmeback_form.telephone.value = temp.replace(/^003530/, "00353");
        return true;
        }

            if (temp.match(/^(\+44 )([3-6]{1}|[8-9]{1}|0|1)/))
             {
            alert("Please enter a valid UK Phone number including area code");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }

            if (temp.match(/^\+44/) && temp.length < 13)
             {
             alert("The number you have entered with this prefix (+44) is too short, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
             
              if (temp.match(/^\+44/) && temp.length > 13)
             {
             alert("The number you have entered with this prefix (+44) is too long, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
             
              if (temp.match(/^0044/) && temp.length < 14)
             {
             alert("The number you have entered with this prefix (0044) is too short, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
              if (temp.match(/^0044/) && temp.length > 14)
               {
             alert("The number you have entered with this prefix (0044) is too long, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
             if (temp.match(/^00353/) && temp.length < 13)
               {
             alert("The number you have entered with this prefix (00353) is too short, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
             if (temp.match(/^00353/) && temp.length > 13)
               {
             alert("The number you have entered with this prefix (00353) is too long, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }             
             if (temp.match(/^\+353/) && temp.length < 12)
               {
             alert("The number you have entered with this prefix (+353) is too short, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
             if (temp.match(/^\+353/) && temp.length > 12)
               {
             alert("The number you have entered with this prefix (+353) is too long, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
            if (temp.match(/^01/) && temp.length < 11)
               {
             alert("The number you have entered is too short, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
             if (temp.match(/^01/) && temp.length > 11)
               {
             alert("The number you have entered is too long, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }             
            if (temp.match(/^02/) && temp.length < 11)
               {
             alert("The number you have entered is too short, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
             if (temp.match(/^02/) && temp.length > 11)
               {
             alert("The number you have entered is too long, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }    
            if (temp.match(/^07/) && temp.length < 11)
               {
             alert("The number you have entered is too short, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
             if (temp.match(/^07/) && temp.length > 11)
               {
             alert("The number you have entered is too long, please check and try again");
            document.callmeback_form.telephone.focus();
            document.callmeback_form.telephone.style.background = '#FF8600';
            document.callmeback_form.telephone.style.border = "1px solid #A5ACB2";
            document.callmeback_form.telephone.style.width = "132px";
            document.callmeback_form.telephone.style.height = "15px";
             return false;
             }
            if (!temp.match(/^(\+44[0-9]{10}|0044[0-9]{10}|0[0-9]{10}|\+353[0-9]{8}|00353[0-9]{13})$/) ) 
            {
            alert("Please enter a valid UK Phone number including area code");
            return false;
            }    
         
}
//-->
</script>
Thanks again Rakuli!!
Reply With Quote
  #7 (permalink)  
Old Oct 29th, 2007, 12:42
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using .match

Hey,

Ive fixed it now by using....
Code: Select all
if (temp.match(/^(\+443|\+444|\+445|\+446|\+447|\+448|\+449)$/))
Thanks for your help rakuli!!
Reply With Quote
  #8 (permalink)  
Old Oct 29th, 2007, 12:42
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using .match

Hmm, usually pretty good with regex but haven't used in a while - not sure why it's not matching...

if (temp.match(/^(\+44[3-6]{1}|\+44[8-9]{1}|\+44[0-1]{1})/))
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #9 (permalink)  
Old Oct 30th, 2007, 09:51
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [SOLVED] using .match

Thanks Rakuli.

Always helpfull!
Reply With Quote
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need assistance verifying that two emails match in a form - please help! Thank you! vanbot JavaScript Forum 1 Jun 12th, 2008 21:55
[SOLVED] 1 solved problem causes another delusion Web Page Design 9 Dec 21st, 2007 08:12
Adding "Topic Solved" for solved topics AdRock Webforumz Suggestions and Feedback 21 Oct 4th, 2007 15:08
innerHTML and innerHTML match DregondRahl JavaScript Forum 2 Jun 11th, 2007 13:24
Photoshop Tennis Match 1 - Billydakid Vs Sirkent Webforumz Staff Graphics and 3D 13 Feb 10th, 2004 16:22


All times are GMT. The time now is 04:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43