Results 1 to 2 of 2

Thread: Forcing Numbers to be entered into a text box.

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Forcing Numbers to be entered into a text box.

    I have a textbox called txtCapacity.

    I would like this to be limited to 3 numerical chars...ie number range from 0 to 999.
    I can use a RegularExpressionValidator control and set it's ValidationExpression to \d{3}.
    However, I would prefer it if I wasn't allowed to enter the word "Woof" at all, as using the above it only traps this on postback.

    I have the following JS:
    VB Code:
    1. var phone = "()- 0123456789";
    2. var numb = "0123456789";
    3. var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    4. function res(t,v){
    5. var w = "";
    6. for (i=0; i < t.value.length; i++) {
    7. x = t.value.charAt(i);
    8. if (v.indexOf(x,0) != -1)
    9. w += x;
    10. }
    11. t.value = w;
    12. }
    Then you add:
    Code:
    onkeyup="res(this,phone);"
    This can be found on:

    http://www.felgall.com/jstip44.htm

    Now what would others do?

    Woof

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: Forcing Numbers to be entered into a text box.

    Maybe something like:

    [code]
    if (! n.NaN)
    if ((n >=0) && (n <= 99))
    alert('number 0 <= n <= 999');
    [/Highlight]
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width