At the moment, I am utilizing Angular 5 and attempting to validate a URL in the following manner:
Here is the HTML code snippet:
<div class="form-group col-sm-6">
<input formControlName="s_url" type="url" class="form-control" id="kk" placeholder="url">
<error-display [displayError]="isValid('s_url')" errMsg="This field is required!"></error-display>
</div>
Within the validate.ts
file, you will find this pattern for validation:
s_url: new FormControl('', [
Validators.required,
Validators.pattern("/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/")
]),
However, even when entering a correct URL, an error message still displays due to the pattern.