0

i need to control the numer of characters enter by the user on a single textbox, but i don't know how, for example y have this

$.validator.addMethod('selectNone',
                    function(value, element) {
                        return this.optional(element) ||
                        (value.indexOf(" ") == -1);
                    }, "Por Favor Selecciona una Opción");

how can i create a rule that control that the use just enter 6 characters (alfanumeric) and how can i control that the user can enter max a number 999,999,999.99 (i can control that the user if doesnt enter the "," and my textbox add it when the user finish a number like 55555.55 and transform it to 55,555.55 (the "." should be always entered by the user if they are going to enter decimals)

thanks

Alejandro Hinestrosa
  • 491
  • 4
  • 11
  • 23

1 Answers1

2

Is this actually 2 questions? how to limit the number of chars and how format what the user has entered.

You can limit the length just in HTML by using the maxlength property on the input element

<input type="text" id="YourTextbox" name="YourTextbox" maxlength="20" />

For the formatting have a look at this question... Add comma to numbers every three digits

Also - if you're using JQuery validator http://docs.jquery.com/Plugins/Validation/Methods/maxlength

For the regex - have a look at this question too Insert commas into number string

Community
  • 1
  • 1
Dave
  • 2,552
  • 5
  • 25
  • 30
  • thanks!!! it helps a lot, i´m readding the other article, i want to use a regular expretion on mi validator.addMetod, how should it be for validate the numer of characters, or validate a numeber with 'x' integers and 'y' decimals? – Alejandro Hinestrosa Apr 12 '12 at 15:39
  • by the way thanks!! , as always i forget to look at the jquery page for this things! :( .. if someone knows how to handle those formats on regex it would be great! thanks for all the help! – Alejandro Hinestrosa Apr 12 '12 at 15:50