Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers by Nicholas C. Zakas; ISBN: 9780764579080
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 17th, 2009, 04:51 PM
Registered User
 
Join Date: Feb 2009
Location: Ohio, USA
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default RegEx Example question

Hi:

I am referring to the example on p.222 at the very bottom (the two alerts). The books says that the isValidEmail function can be called using the alerts. I don't understand how that works. It seems to imply this function can be called by inserting the alerts. I don't see how that would work. What am I missing here. Any help is appreciated.
Reply With Quote
  #2 (permalink)  
Old February 17th, 2009, 06:34 PM
Authorized User
 
Join Date: Dec 2008
Location: London
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

hi

i am afriad i don't have the book but if you post more details i will be able to help you .

Thanks
Reply With Quote
  #3 (permalink)  
Old February 17th, 2009, 09:12 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Agree w/ zeronexxx, but I *suspect* they simply mean you can do
Code:
if ( ! isValidEmail( someFormField ) ) alert("Doofus...I wanted your email address");
But you'll almost always get more responses (and correct responses) if you show the actual code so that those without the book can understand your question.
Reply With Quote
  #4 (permalink)  
Old February 17th, 2009, 09:56 PM
Authorized User
 
Join Date: Dec 2008
Location: London
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

or may be something like


PHP Code:

function isValidEmail(EmailField){
    var 
regex = /[a=zA-Z0-9_\-]+@[a-zA-Z0-9\-.]/;
    if(
regex.match(EmailField.value)){
       return 
"this is valid email";
    }else{
       return 
"this email is invalid";
    }
}


alert(isValidEmail(someEmailField)); 
Reply With Quote
  #5 (permalink)  
Old February 17th, 2009, 10:07 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Good guess!

Of course, it's weird if either of us is right, because then how does the validation cancel the form submittal???

Ugh.
Reply With Quote
  #6 (permalink)  
Old February 18th, 2009, 02:46 PM
Registered User
 
Join Date: Feb 2009
Location: Ohio, USA
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Followup to my RegEx question ...

Thank you all for the responses!

My regrets for not listing all information. The information I was questioning is located on p.222 of JavaScript for Web Developers, Nicholas C. Zakas. In it the author discusses validating e-mail addresses using RegEx techniques. He discusses the major email formats and offers a RegEx validation solution:

function isValidEmail(sText) {
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
return reEmail.test(sText);
}

He then goes on to add in the next line:

"This function can be called like so:


alert(john.doe@somewhere.com); //outputs "true"

alert(john.doe@somewhere.); //outputs "false" "

(The underlining on the email addresses are not in the book but were added by default in this editor.)

And that is where my confusion comes in. I am unaware of how the function can be called given the code as laid out in the book. Of course the RegEx works but I don't see how the function can be invoked using just an alert. I thought it was just a typo but the errata pages for the book does not address it. Do you have any info that can shed light?

Regards,
Bill Wayne
Reply With Quote
  #7 (permalink)  
Old February 18th, 2009, 04:08 PM
Authorized User
 
Join Date: Dec 2008
Location: London
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

Hi Bill

I am afraid that what you have expressed above clearly is not the case, following is the actual code. I downloaded the code and here is the full code.

PHP Code:
<html>
    <
head>
        <
title>E-mail Example</title>
        <
script type="text/javascript">
    

                function 
isValidEmail(sText) {
                    var 
reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
                    return 
reEmail.test(sText);
                }

                
                function 
validate() {
                    var 
oInput1 document.getElementById("txt1");
                    if (
isValidEmail(oInput1.value)) {
                        
alert("Valid");
                    } else {
                        
alert("Invalid!");
                    }

                }
        
</script>
    </head>
    <body>
        <p>E-mail Address: <input type="text" id="txt1" /><br />
        <input type="button" value="Validate" onclick="validate()" /></p>
       
    </body>
</html> 
Hopefully the confusion is clear now?

Regards
Reply With Quote
The Following User Says Thank You to zeronexxx For This Useful Post:
williamjwayne (February 18th, 2009)
  #8 (permalink)  
Old February 18th, 2009, 09:57 PM
Registered User
 
Join Date: Feb 2009
Location: Ohio, USA
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for the info regarding the errata correction -- I had seen that so I guess my question has been answered. I just wanted to make sure that there was not something that I was missing.

Regards,
Bill Wayne
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex pendemv JSP Basics 4 December 8th, 2008 08:29 AM
Regex question in Java rangalo Java Basics 2 October 26th, 2006 09:26 AM
RegEx Question - Disregard dparsons ASP.NET 1.0 and 1.1 Professional 0 August 24th, 2006 09:30 AM
More regex help Snib Pro PHP 4 December 16th, 2004 09:56 PM
Regex Help boyer99g General .NET 2 October 8th, 2004 05:46 PM



All times are GMT -4. The time now is 10:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.