Jagankumar Jagankumar - 2 years ago 196
HTML Question

regex validations for textarea angular

I would like to validate a my textarea field using regex in my angular app. but their will be a certain conditions for textarea.

      1. Message should not be more than 500 characters.

      2. Text should not consecutive space characters.

      3. No word should be more than 20 characters.

      4. There should not be consecutive special characters.

<textarea id="message" name="message" type="text" placeholder="" required="" ng-maxlength="500" ng-model="message" ng-pattern="/^[a-zA-Z0-9]{5}$/" class="form-control"></textarea>

any help will be appreciated.

Answer Source
  1. done ng-maxlength="500"

  2. \x20{1}/g - not consecutive space characters

  3. \W{20,}/g - no word at least 20 chars

  4. [^\s]{1}/g - not be consecutive special characters

try this ng-pattern="/(\W{20,}|\x20{1}|[^\s]{1})/g"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download