A
A
Alex102142020-11-28 15:39:29
Angular
Alex10214, 2020-11-28 15:39:29

How to create a validator that checks the beginning of a link?

Hello, the task is to create an input in which a link to an image is entered. How to create a validator that checks the beginning of a link for http:// ? Everything is written through reactive forms. Please tell me how..

addressIcon: new FormControl('', [Validators.required, Validators.(Что тут должно быть??) ]),

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2020-11-28
@Alex10214

addressIcon: new FormControl('', [Validators.required, Validators.pattern('https?:\/\/(www\.)?[[email protected]:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)') ]),

A
Alex10214, 2020-11-28
@Alex10214

Thank you very much) Here is my working version: I
Validators.pattern(['http://.+'] ['https://.+'])
just check that http is in the beginning. Thanks again)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question