0

I'm working on some forms for a Website. Currently I have the usual HTML Browser check (with "required"-tag and patterns and stuff in the inputs), I check the values in a JavaScript before submitting and I do a server-sided check of the data after submitting.

Everything works fine, even if I have only one of them enabled, but it seems a little bit overkill to me, so my question is if I can just leave the Javascript check out? Of course I need to keep the server chek :D

Looking forward to your answers!

2
  • 1
    You can never trust your client. Javascript validation is only used to improve UX. Commented Mar 3, 2016 at 13:00
  • server side validation is must and some older browsers will not validate with "required" tag. so you need to write custom JavaScript code to validate in the client side(if you want). Commented Mar 3, 2016 at 13:00

3 Answers 3

1

You must always validate input at serverside. Javascript is optional and it just to make life of your users easier. Your users get better experience. That's it.

Sign up to request clarification or add additional context in comments.

2 Comments

that's what I thought. I think I'm going to keep it this way.
It's the same question like "do you need AJAX"? No not really but you do make nice pages that don't need to reload every time you use it. -> better experience.
1

All modern browsers support the HTML5 form field attributes. As you are using those, you may skip the JS validation.

5 Comments

As far I know IE 8 and 9 have problems supporting it. (if no support at all)
@PVL Yes, but I wouldn't say these are modern browsers. And if you have to target those browsers, you may just work with the server-side validation, instead of implementing a JS solution only for those browsers. But this depends on which browsers the target audience uses. (Check you websites statistics to know…)
I prefer to implement javascript/jQuery once and forget about problems with other browsers. Not to mention you get nicer validation and you can let user know in a nice way what went wrong.
@PVL But “implement javascript/jQuery once” is an extra task that you have to get paid for by customers – just using your modern CMS' forms out of the box is not…
Yes but a lot CMS' use javascript to be pretty, that's my point :P
0

To expand a little on the current answers:

Server side validation is always required, you mentioned that.

HTML and Javascript validation are used for different things.

The HTML required tag can be used to check a form's fields are not blank before a form submission.

Javascript validation allows you to be far more flexible with what you want to validate and when. However, it requires more work because it's not as simple as a required tag.

With Javascript you can do far more. Some examples:

  • Validation that occurs as soon as a user starts to type
  • Have the box highlight a different colour
  • Show an error message
  • Have a big red cross appear next to invalid fields or a big green one next to valid ones
  • Spin your page around when the user enters something invalid. (don't actually do that)
  • etc.

Also note browser support for the required tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.