Link to home
Start Free TrialLog in
Avatar of Netwing
NetwingFlag for Austria

asked on

JSP Serverside Email Validation

Hi,

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

thx for help
ASKER CERTIFIED SOLUTION
Avatar of jimmack
jimmack

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>
Avatar of jimmack
jimmack

;-)

I would have said the same thing (if I understood more about JavaScript ;-))
Avatar of Netwing

ASKER

thanks for the help jimmack.

the discussion about serverside or not is a philosophy one... i prefer serverside because this one cant be disabled :-)
;-)
Hi Netwing.
What do you mean with?
>>... i prefer serverside because this one cant be disabled
Just curiosity.
Javier
Avatar of Netwing

ASKER

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.
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
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 ;-)
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

I like that one ;-)