0

I have this validation check:

if (isNaN($scope.QuickQuoteData.RequestedAmount)) {
    $scope.ShowValidation = true;
    $scope.errors.push('Requested amount has invalid value.');
}

But what I want to allow is for example if user will enter values in this format:

€ 1500000
€ 1.500.000
1.500.000

Then I need to allow the operation to continue instead of throwing validation error.

So every other format will be invalid except the input values in the formats above.

Any idea how can I tweak that?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Laziale
  • 7,965
  • 46
  • 146
  • 262
  • 3
    Use a regular expression. There's a lot around for validating currency strings if you search. – Rory McCrossan Jul 18 '16 at 08:32
  • I think Intl(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) object has some support for parsing numeric inputs based on different locales . – Anthony Jul 18 '16 at 08:35
  • Hi you can have a look here, but consider that in the linked example they use the dollar sign, and they use commas and dots in the opposite way compared to your example (I guess you want comma for decimals and dot for thousands/millions etc.)... http://stackoverflow.com/questions/16242449/regex-currency-validation – mastazi Jul 18 '16 at 08:37

2 Answers2

1

you can check with below method

if (!("Any Number with special chars".test(/^[a-zA-Z]+$/))) { ... }

This will check if provided number has String or not will not check for Special Chars...

pareshm
  • 4,874
  • 5
  • 35
  • 53
0

As my understating for your requirement, you can do somthing like this.

var specialChars=[".", "$", "€"]; //Add your symbols whatever you need.

function validate(val){
  for(var i=0;i<val.length;i++){
    if(specialChars.indexOf(val[i]) >= 0) {
      continue;
    }
    if(isNaN(val[i])) {
      return false;
    }
  }
  return true;
}
Sanjay Nishad
  • 1,537
  • 14
  • 26