JS with no special characters and blank spaces

Yes that’s right. You aren’t using the submit event to validate and submit the form, so the validation does not occur.

and the entirity of the validate() function as currently written can be replaced by putting the ‘required’ attribute into the FirstName and Lastname fields, for that matter.

Yes that’s right. Form validation has been built in to web browsers for a long time now.

Are you talking about the validation on your code or the validation on my existing code which does work because the alert works if you miss a field?

The web browser does its own in-built validation of the form when the form submit event occurs. My code example at https://jsfiddle.net/pmw57/2zqcqpzx/1/ works because the button is a submit button (it has a type of “submit”) which causes the form submit event to trigger. That submit event, is what causes the validation to occur.

Your form currently doesn’t use the submit event, which is why you are not seeing any form validation take place.

I changed “button” to “submit”.

It still allows me to submit with bad characters unless I leave out the field above it blank, which is required. I get the alert that it is a required field and then your code kicks in with the red box. If I have all fields and get no alert from my code, I can submit with the bad characters.

I recommend that you put together a simple version of the HTML and JavaScript code, for us to explore the problem.

Will do, thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.