0

I am using vuelidate library to validate the URL. I wanted input only to accept specific URL types. They are "http://www.example.com", "https://www.example.com", "www.example.com" . If entered URL not matched with the above-mentioned patterns, then I need an error. Below is my code

import { maxLength, url } from "vuelidate/lib/validators";
export default {
  data() {
    return {
      form: {
        homepageUrl: null,
      },
    };
  },
  validations: {
    form: {
      homepageUrl: { url, maxLength: maxLength(150) },
    },
  },
}

Note: It could be any domain like .net .co.in .com .it .av .let

Sam
  • 149
  • 4
  • 15
  • What do you mean by "other than these"? What about `https://example.com`? `https://example.io`? `https://example.co.uk`? `https://www.example.com:8080/`? Are URLs with hashes/query strings allowed? – Terry Jun 24 '21 at 11:27
  • @Terry, now I updated the question, please check. I wanted input only accepts patterns is "http://www.example.com", "https://www.example.com", "www.example.com". – Sam Jun 24 '21 at 11:34
  • So all other top level domains will be rejected? Like `https://example.org`? – Terry Jun 24 '21 at 11:38
  • See: https://stackoverflow.com/questions/1410311/regular-expression-for-url-validation-in-javascript – Terry Jun 24 '21 at 11:41
  • no, it could be any domain like .org, .net .co.in .com .it .av .le – Sam Jun 24 '21 at 11:43
  • Then do update your question because it is misleading and doesn't accurately show what you intend the validation to do. The best approach with these questions is to give multiple examples of what is considered valid _and_ invalid. – Terry Jun 24 '21 at 11:46

0 Answers0