Validating checkbox using javascript


16-Jun-2019 08:18

To add a validation prompt, add the following line of code to your form, just under your input field.

This will clean up the prompt message once the user corrects their mistake.

To create a validation for your name field, type the following line into your and assign it the regex of any capital letter (A-Z), any lower case letter (a-z), a space, a hyphen or an apostrophe.

With this regex rule saved, we can then run a test on our input to see if what was entered matches our defined rule. Save this out and refresh the page in your browser.

validating checkbox using javascript-14

Live cam chat no login no register no credit

A much better way of solving this problem is to include inline validation that checks the user’s input as she progresses.

event allows you to run Javascript code when the user clicks away from the field. In order to validate the input, we have to test it against a set of rules that define a pass or fail.

In this case, we want to be able to validate what the user has entered into the field, but we only want to do that when she has finished typing and has moved on. As you can see, I’ve already named the Javascript function that we are going to make in a minute and I’ve passed in the name of the the field, in this case “name”. In between the So hopefully you can see how the Javascript is run when it is triggered, and how we are able to get whatever the user has typed into the input box and do something with it. For example, you don’t want your users to enter & or @ or % into your name field because these characters don’t belong there.

As I mentioned before, information is passed to the validation function in the event object, and in the code we see that the member ‘value’ is used to communicate the current value of the field.

The member ‘rc’ (or return code) is used to communicate back if the validation was successful or not.This is handy because we don’t really want to allow our user to submit a form with invalid data.



Electric green and red tears flowed down his furry cheeks. One of several scenarios is about to unfold, so prepare yourself.… continue reading »


Read more