0

Hi I want to validate a textangular box which will have a lot of text, but I don't want to allow telephone numbers, email ids or any URLs in this text box. I want to show the error message as the email/telephone/url if mentioned in the text box as well and say that is not allowed.

Using ng-Pattern, please tell me what regex to use to allow this.

<div class="form-group">
    <div class="col-sm-6 col-md-8">
        <label for="inputjobDescription" class="control-label lightfont">Description</label>
        <div text-angular ng-model="job.Description" name="description" ng-pattern="/^((([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6}))\n?)*$/" ng-minlength="100" ta-min-text="100" required>
        </div>
        <p ng-show="jobform.description.$invalid && !jobform.description.$pristine && !jobform.description.$error.pattern" class="help-block">Can you be a bit more elaborate(atleast 100 characters) , please?<br> Don't write your emailID, telephone number or any URL.</p>
    </div>
</div>

My current ng-pattern is as follows

ng-pattern="/^((([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6}))\n?)*$/"
jcc
  • 1,137
  • 1
  • 12
  • 31
aksit
  • 69
  • 1
  • 6

1 Answers1

0

This doesn't look like a good spot for a regex. A regex would probably be too complicated here.

I would suggest to use a custom validator here and try it the other way around:

Compare the given text with 3 different regexes:

  1. Is there any phonenumber in it ?
  2. Is there any email in it ?
  3. Is there any hyperlink in it ?

Only if ALL these three (better manageable) expressions FAIL you are ok and return that the expression is valid. In this case you can use three standard regexes from a casual google search instead of inventing some mindblowing super-regex if you know what i mean.

Patrick Kelleter
  • 2,631
  • 1
  • 13
  • 19