0

I want an ng-pattern expression to validate a textbox in AngularJS JavaScript. Contents for this textbox must have at least one Alphabetic character, but may also contain any number of Numeric and/or Special characters.

Examples:

  1. a1234$ It is acceptable (because 'a' is present)
  2. 123% It is not acceptable
  3. abc It is acceptable
  4. 56456a It is acceptable
  5. 123$%^abc It is acceptable
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • 1
    Please post what you have tried so far. – Khalid Hussain Apr 25 '16 at 11:08
  • Please note that this is a question and answer site, not a code writing service. If you [edit] your question to describe what you have tried so far and where you are stuck, then we can try to help with specific problems. You should also read [ask]. – Toby Speight Apr 25 '16 at 17:38

2 Answers2

1

Use ng-pattern like this.

<input type="text" ng-model="price" name="price_field" ng-pattern="/.*[a-zA-Z]+.*/" required>
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
user3045179
  • 321
  • 4
  • 20
0

If all you need is to check if there is atleast one alphabet in the string you're matching then you can use the following pattern :

".*[a-zA-Z]+.*"
Salander
  • 184
  • 2
  • 12