JavaScript Validation Examples

We can validate input controls using JavaScript easily. Below are a few JavaScript validation examples.

Textbox required validation in javascript

By using JavaScript, we can validate for empty value in textboxes. Whenever an user tries to submit a form without entering a value in the textbox, it will display mandatory field validation messages in an alert box.

<script type='text/javascript'>
function textBoxValidation()
if(document.getElementById('txtBox').value.trim()== "")
alert('Textbox should not be blank');
return false;
alert("Your name submitted sucessfully")
return true;
Name:<input type='text' id='txtBox'/> <input type='button' onclick="textBoxValidation()"id="btnSubmit" value='Submit' />

Leave a Reply

Your email address will not be published. Required fields are marked *