简体   繁体   English

Angular 6 URL模式验证器

[英]Angular 6 url pattern validator

In an input form Angular 6 I want to check if the input url supposed to contain the Facebook url really is a valid url which contains as substring either the string “facebook.com” or “fb.me” and if it is not the case return an error message. 在输入表格Angular 6中,我想检查应该包含Facebook网址的输入网址是否确实是有效的网址,该网址包含字符串“ facebook.com”或“ fb.me”作为子字符串,如果不是,返回错误信息。

Im stuck with the following: 我坚持以下几点:

<div nxRow>
  <div nxCol="12">
    <nx-formfield nxStyle='negative' nxLabel="FACEBOOK">
      <input nxInput type="url" ng-model="facebook" pattern="^.*facebook.com*$/" value="{{facebook}}">
      <span nxFormfieldHint>
                  Link zur Facebook
              </span>
    </nx-formfield>
  </div>
</div>

You could try adding a dot before the * like ^.*facebook.com.*$ to match any character zero or more times. 您可以尝试在*之前添加一个点,例如^.*facebook.com.*$以匹配任何字符零次或多次。

Right now you are repeating the m zero or more times. 现在,您正在重复m次零次或多次。

To check if the string contains either facebook.com of fb.me you might use an alternation : 要检查字符串是否包含fb.me的facebook.com,您可以使用替代方法

^.*(?:facebook\\.com|fb\\.me).*$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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