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 →

Hashing Passwords-Easier Password Management by creating and storing the salt and the hashed password in a single value.

Include header using System.Web.Helpers; In View: To take input <div class="col-sm-4 tb-font"> @Html.Label("UName", "User Name", new { style = "width:140px; margin-bottom:5px; margin-top:5px; float: left;" }) @Html.TextBox("UserName", null, new { @class = "form-control text-box" }) </div> <div class="col-sm-4 tb-font"> @Html.Label("Pswrd", "Password", new { style = "width:140px; margin-bottom:5px; margin-top:5px; float: left;" }) @Html.Password("Password", null, new { @class... Continue Reading →

Return bool value from ajax

Returning bool value from ajax is not similar to any simple function that returns the bool value. BUT DON'T WORRY! it isn't even too difficult. it's just slightly different. Solution var alreadyExists = function () { var role = $("#UserRole").val(); var notexists = false; $.ajax ({ url: "@(Url.Action("checkExists", "UserManagement"))", data: { role: role }, contentType:... Continue Reading →

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started