Hi yogesjoshi,
To validate id (number) and name (alphabet and space) while updating you have to use JavaScript validation.
Refer the below code.
//Update event handler.
$("body").on("click", "[id*=tblCustomers] .Update", function () {
var row = $(this).closest("tr");
$("td", row).each(function () {
if ($(this).find("input").length > 0) {
var span = $(this).find("span");
var input = $(this).find("input");
span.html(input.val());
span.show();
input.hide();
}
if ($(this).find("select").length > 0) {
var span = $(this).find('span');
var select = $(this).find("select");
span.html($(this).find("select").find("option:selected").text());
select.hide();
span.show();
}
});
row.find(".Edit").show();
row.find(".Delete").show();
row.find(".Cancel").hide();
$(this).hide();
var customerId = row.find(".CustomerId").find("span").html();
var name = row.find(".Name").find("span").html();
var country = row.find(".Country").find("option:selected").text();
// Allow only alphabet and space
var alphabeticValidation = /^[a-zA-Z ]*$/;
if (!alphabeticValidation.test(name)) {
alert("Only alphabetic characters allowed.");
return false;
}
// Allow only numeric value
var numericValidation = /^[0-9]*$/;
if (!numericValidation.test(customerId)) {
alert("Only numeric value allowed.");
return false;
}
var customer = {};
customer.CustomerId = customerId;
customer.Name = name;
customer.Country = country;
$.ajax({
type: "POST",
url: "/Home/UpdateCustomer",
data: '{customer:' + JSON.stringify(customer) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json"
});
});