简体   繁体   中英

Exclude “http” or “http://www.” from angularjs form

I search how to exclude

http

and with the 'www' from a textarea :

            <div id="textareaPart">
                <label for="textarea" class="col-sm-2 control-label">
                    Your message
                    <span class="myForm_error" ng-show="myFormZR.textarea.$error.required">(champ needed)</span>
                    <span class="myForm_textarea" ng-show="myFormZR.textarea.$dirty"> - characters : {{0 + myForm.textarea.length}} / 500</span>
                </label>
                <div class="col-sm-10">
                    <textarea class="form-control" name="textarea" rows="3" required="required" placeholder="500 characters max..." maxlength="500" ng-model="myForm.textarea"></textarea>
                </div>
            </div>

it's ng-pattern ? i know how to allow with a regexp but how to exclude ?

You can do the following:

ng-pattern="/^((?!www|http[s]{0,1}:\/\/www).)*$/";

This will allow every value except if it contains:

  • www
  • http://www
  • https://www

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM