Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JSP Serverside Email Validation

Posted on 2003-12-09
11
Medium Priority
?
1,215 Views
Last Modified: 2008-02-01
Hi,

i need a simple serverside jsp email validation.
Checking if the @ and a . is in the string

thx for help
0
Comment
Question by:Netwing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 15

Accepted Solution

by:
jimmack earned 200 total points
ID: 9904394
if ((emailString.indexOf("@") != -1) &&
    (emailString.indexOf(".") != -1))
{
    // Contains a '@' and a '.'
}

Perhaps better would be:

if ((emailString.indexOf("@") != -1) &&
    (emailString.indexOf(".", emailString.indexOf("@")) != -1))
{
    // Contains a '@' with at least one '.' after it.
}
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9904656
Hi.

Jimmack is totaly right. But, Why you want to do it at server side, you should better check it a the Client, if you're not going to process the request if the email in not properly set.

I think you should do it with JavaScript instead of Java, and is exactly the same code.

Javier

<script>
function checkEmail() {

var emaiString=document.form1.email.value();

if ((emailString.indexOf("@") != -1) && (emailString.indexOf(".", emailString.indexOf("@")) != -1)) {
    // Contains a '@' with at least one '.' after it.
} else {
alert("The email you have introduced, is not valid);
document.form1.email.setFocus();

}
}
</script>

<form name="form1" ......>
<input type=text name=email onBlur="javascript:checkEmail();">
</form>
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9904725
;-)

I would have said the same thing (if I understood more about JavaScript ;-))
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:Netwing
ID: 9904841
thanks for the help jimmack.

the discussion about serverside or not is a philosophy one... i prefer serverside because this one cant be disabled :-)
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9904861
;-)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9904905
Hi Netwing.
What do you mean with?
>>... i prefer serverside because this one cant be disabled
Just curiosity.
Javier
0
 
LVL 2

Author Comment

by:Netwing
ID: 9910522
Javascript is client side scripting and can be disabled in the browser if the user whant. And there should be no way to disable bypass or fake a validation. So validation on the server is the better way. But thats what i think- its how i wrote more a philosophy thing.
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9910898
Well Netwing.
I do understand that, but if you're planning to make an application that works fast I believe serverside validations for those kind of things are out of mind, if you want to be sure the user hasn't disabled the Javascript there are ways to know it, besides you should think if you want someone with that option disabled enter your application. is not that I like much Javascript but is the faster way to make your online validations, and don't be submited to just HTML, is just like if you want to make an application with Flash and you don't do it becose maybe the user don't have the plugin and he don't want to download it. What is more important your application or your user?
Anyway I'm not trying to change your mind, I guess your choice is just ok while you don't have to make to many validations. just tell you that it takes time and server resources wich are expensier that client ones.
Javier
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9911016
Just to add my two penneth ;-)

There is also a security issue with the JavaScript solution.  It's probably not that important in this particular case, but there would be nothing to stop an end user copying the source of the page and modifying the JavaScript (or removing it entirely) in order to enter any data they want.

As I say, in this case, it's probably not that important, but it might be for other solutions, so it's probably worth pointing out ;-)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9911327
Well to be honest.

I left no track of my code on the client, but the images, no HTML or SCRIPT is been able to be modified if you put this on your JSP and disable the right button on the BODY too:

<%
      response.setHeader("Cache-Control", "no-cache");
      response.setHeader("Pragma", "no-cache");
      response.setDateHeader("max-age", 0);
      response.setDateHeader("Expires", 0);
%>

<BODY...........  onContextMenu="return false">

Is a good trick you can test.

Javier

0
 
LVL 15

Expert Comment

by:jimmack
ID: 9911365
I like that one ;-)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question