Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Regular Expression

    I want to validate a form with only numbers and "$" sign.
    so far i know this
    Code:
    		currencyValue = which.value;
    		var re = /^[0-9]*$/;
    		if (!re.test(currencyValue)) {
    		    alert("Value must be all numberic charcters, non numeric's removed from field!");
    		    field.value = field.value.replace(/D/g,"");
    		}
    but how do I also add the "$" sign as ok?

  • #2
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ah, got it guys... my Reg Ex should be
    Code:
    /^[0-9\,\.\$]*$/

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    field.value = field.value.replace(/D/g,"");

    That will replace the capital letter D with "" (nothing).

    Try

    field.value = field.value.replace([^0-9\,\.\$]/gi, "");


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.


  •  

    Posting Permissions

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