Skip to content Skip to sidebar Skip to footer

Jquery Regex To Allow Only A Currency Symbol And Numbers

I'm using jQuery's validation plugin to validate form text fields. I'm trying to validate a price field by only allowing currency symbols, letters and numbers but no other special

Solution 1:

You should use regex pattern ^[a-zA-Z0-9€£]+$

Even your wrong pattern does not allow characters such as ;, " or :. You must have some error in your code, not just in regex pattern.

UPDATE [1]

If you want to allow also space character, then use regex pattern ^[ a-zA-Z0-9€£]+$

UPDATE [2]

If you want to allow also decimal numbers, you need to allow dot as well: ^[. a-zA-Z0-9€£]+$

UPDATE [3]

JavaScript Form Validation

<formname="myForm"action="form.php"onsubmit="return validateForm()"method="post">

...with script:

functionvalidateForm()
{
  // iferrorreturnfalse;
  // if okay  returntrue;
}

Post a Comment for "Jquery Regex To Allow Only A Currency Symbol And Numbers"