Validate form to check if any text box is empty on submit

Solution Call this function on submit or save button to validate the form. var checkEmpty = function () { var formInvalid = false; $('#MyForm').each(function () { if ($(this).val() === '') { formInvalid = true; } }); if (formInvalid) { alert('One or more fields are empty. Please fill up all fields'); return false; } else return... Continue Reading →

Function to validate name for numbers and special characters

Solution In Jquery var ValidateName= function (usr) { var regexp = new RegExp('^[A-Za-z]+$'); var check = $(usr).val(); if (!regexp.test(check)) { alert('Numbers and Special Characters are not allowed'); $('#UserRole').css('border-color', 'red'); return false; } else { $('#UserRole').css('border-color', 'green'); return true; } } HTML <div class="col-sm-4 tb-font"> @Html.Label("Role", "User Role", new { style = "width:140px; margin-bottom:5px; margin-top:5px; float:... Continue Reading →

Function to Compare text of Password and Confirm Password field and placing it in document.ready function

Solution <script> $(document).ready(function () { $('#Password, #CPassword').on('change', function () { var ps = $("#Password").val(); var cps = $("#CPassword").val(); if (ps != null && ps != '' && cps != null && cps != '') { if (ps != cps) { alert("Please Enter the same Password in both fields"); $('#Password').css('border-color', 'red'); $('#CPassword').css('border-color', 'red'); } else {... Continue Reading →

Call a function when the view loads in an MVC application

Solution Document.ready function is for this purpose. For example, you want to call a function that fills a drop-down dynamically when the view loads, you will give that function a call in document.ready function enclosed in the script tag <script> $(document).ready(function () { fillRoles(); }); </script> In the above example, function fillRoles() is called to... Continue Reading →

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started