Reputation: 97
I have a Gridview with contain Textbox. I want to validate this textbox with textbox keypress event
Upvotes: 0
Views: 1387
Reputation: 49
You can validate through javascript.
Client side validation: search these file and add in your project:
Then add reference to your page in script tag and css in link tag.
Give id to textbox and use class="validate[required,custom[integer]"
, then write a script like this:
$(document).ready(function () {
$("#textboxid").validationEngine('attach', { scroll: true, promptPosition: "topLeft", showOneMessage: true, autoHideDelay: 3000, autoHidePrompt: true, delay: 500 });
});
If you want to use server side validation then read about requiredfieldvalidator.
Upvotes: 1
Reputation: 1512
If you are using jQuery library in the project then refer this function below.
jQuery.fn.forceNumeric = function () {
return this.each(function () {
$(this).keydown(function (e) {
var key = e.which || e.keyCode;
if (!e.shiftKey && !e.altKey && !e.ctrlKey && key >= 48 && key <= 57 || key >= 96 && key <= 105 || key == 8 || key == 9 || key == 13 || key == 35 || key == 36 || key == 37 || key == 39 || key == 46 || key == 45) return true;
return false;
});
});
}
Assign a cssClass
property to TextBox
like
<input name="txtAny" id="txtAny" class="customonly" />
And in script tags
of page add this below line:
$(document).ready(function () {
$('.customonly').forceNumeric();
});
This will bind the event (forceNumeric) on all TextBox
within a grid template.
For quick reference use the JsFiddle Demo
Upvotes: 0
Reputation: 2568
Regex Validation Help ful to you below regex links available
Regex validation on decimal
Simple regular expression for a decimal with a precision of 2
Upvotes: 0