0

I have a Gridview with contain Textbox. I want to validate this textbox with textbox keypress event

nksingh420
  • 97
  • 1
  • 1
  • 6

3 Answers3

1

You can validate through javascript.

Client side validation: search these file and add in your project:

  1. jquery.validationEngine-en.js
  2. jquery.validationEngine.js
  3. validationEngine.jquery.css

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.

Sumurai8
  • 20,333
  • 11
  • 66
  • 100
0

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

Community
  • 1
  • 1
senthilkumar2185
  • 2,536
  • 3
  • 22
  • 36
0

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

Pratik
  • 1,472
  • 7
  • 20
  • 36