0

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.

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>
3
  • Similar to : stackoverflow.com/a/13821385/7124761 Commented Jun 21, 2018 at 12:48
  • 1
    You're asking about Angular 6 but there's AngularJS (1.x) syntax in your code - which version are you using? Commented Jun 21, 2018 at 12:51
  • Angular 6, my problem is that pattern is not affecting anything Commented Jun 21, 2018 at 12:52

1 Answer 1

1

You could try adding a dot before the * like ^.*facebook.com.*$ to match any character zero or more times.

Right now you are repeating the m zero or more times.

To check if the string contains either facebook.com of fb.me you might use an alternation:

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

Sign up to request clarification or add additional context in comments.

2 Comments

No particular experience on that part but perhaps this page might be helpful.
Hey man, is there a way to obtain the same result and avoid combination with withespaces?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.