[英]How to create decorator to validate image URL in typescript
I have to validate an image by its URI or its type.我必须通过图像的 URI 或类型来验证图像。 If i use this regex pattern it validates only the link (http(s?):)([/|.|\\w|\\s|-])*\\.(?:jpg|gif|png)
ends with this types but in my case it should validate both like.如果我使用这个正则表达式模式,它只验证链接(http(s?):)([/|.|\\w|\\s|-])*\\.(?:jpg|gif|png)
以这种类型结束但在我的情况下,它应该验证两者。 It should accept URL or else file type.它应该接受 URL 或其他文件类型。
Eg:例如:
1) https://thevarsity.ca/wp-content/uploads/2019/09/ARTS-TIFF_REVIEW-COURTESY_PHOTOKINO_LORBER-IMAGE_BOOK_STILL-1080x720.jpg 1) https://thevarsity.ca/wp-content/uploads/2019/09/ARTS-TIFF_REVIEW-COURTESY_PHOTOKINO_LORBER-IMAGE_BOOK_STILL-1080x720.jpg
2) Should accept image types like PNG,JPG,JPEG,GIF. 2)应接受 PNG、JPG、JPEG、GIF 等图像类型。
sdfdsadasdsadsfdsf.png sdfdsadasdsadsfdsf.png
And am looking of the solution.并且正在寻找解决方案。
You can check against multiple regex statements by separating them with |
您可以通过将它们分隔开来检查多个正则表达式语句|
like regex_one|regex_two
像regex_one|regex_two
To check for the end portion say the extension, you can use $ symbol
Hope the below mentioned regex works for you.希望下面提到的正则表达式对你有用。
/(http(s?):)([\/|.|\w|\s|-])*\.(?:jpg$|gif$|png$)|([\/|.|\w|\s|-])*\.(?:jpg$|gif$|png$)/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.