Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics 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 November 28th, 2008, 11:15 AM
Authorized User
 
Join Date: Aug 2008
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regex

Hello All,


I want to validate a text box for email validation using regex. The issue i am facing is:
1) i have 2 textboxes where 1st will carry firstname_lastname
and the 2nd textbox will carry @domain name.

2) I want to validate the first box for firstname_lastname where it should check for the '_' character.

Please help.

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

So do you want to do this client-side in JavaScript or server side in JSP code??? Or, to be safe, do you want to do it both places?
Reply With Quote
  #3 (permalink)  
Old December 1st, 2008, 03:22 AM
Authorized User
 
Join Date: Aug 2008
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want to do this in JavaScript. Thank you

Reply With Quote
  #4 (permalink)  
Old December 1st, 2008, 04:17 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Code:
<script>
function checkForValidName( fld )
{
    var re = /^[a-z]+\_[a-z]+$/i
    // optional:  Trim spaces from ends first:
    var txt = fld.value.replace( /(^\s+|\s+$)/g, "" );
    // optional:  Put the trimmed value back in place
    fld.value = txt;
    if ( ! re.test( txt ) )
    {
        alert("Must be in form firstname_lastname");
        fld.focus();
        fld.select();
        return false;
    }
    return true;
}
</script>
Then invoke that function via something like
     <form onsubmit="return checkForValidName( this.SomeFieldName );">

Note that this RE will allow names as simple as
    a_b
If you want to insist on (say) a minimum of 3 letters in first name and 2 in second, you could do
    var re = /^[a-z]{3,99}\_[a-z]{2,99}$/i

Or use whatever numbers you feel comfortable with.
Reply With Quote
  #5 (permalink)  
Old December 8th, 2008, 08:29 AM
Authorized User
 
Join Date: Aug 2008
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you!

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 mrame XSLT 12 July 25th, 2008 09:37 AM
Regex htran XSLT 2 May 18th, 2005 09:21 AM
More regex help Snib Pro PHP 4 December 16th, 2004 09:56 PM
Need RegEx help Snib Pro PHP 6 November 16th, 2004 06:59 AM
Regex Help boyer99g General .NET 2 October 8th, 2004 05:46 PM



All times are GMT -4. The time now is 05:11 PM.


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