tweak on yup validation
This commit is contained in:
parent
af2b2a6185
commit
2dc8a0c355
|
@ -1,7 +1,7 @@
|
|||
// Fast Image can't render a svg image from a uri yet, because of that we aren't test the svg within the RegEx
|
||||
export const regExpUrlImage = new RegExp(
|
||||
export const regExpImageType = new RegExp(
|
||||
'.(jpg|jpeg|png|webp|avif|gif|tiff)' + // type of the URL
|
||||
'(\\?[;&a-z\\d%_.~+=-]*)?',
|
||||
'i' // query string
|
||||
);
|
||||
export const isImage = (url: string) => regExpUrlImage.test(url);
|
||||
export const isImage = (url: string) => regExpImageType.test(url);
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import fetch from './fetch';
|
||||
|
||||
export const isValidURL = (url: string): boolean => {
|
||||
const pattern = new RegExp(
|
||||
'^(https?:\\/\\/)?' + // protocol
|
||||
|
@ -15,12 +13,3 @@ export const isValidURL = (url: string): boolean => {
|
|||
|
||||
// Use checkUseSsl: false only if server url starts with http://
|
||||
export const isSsl = (url: string): boolean => !/http:\/\//.test(url);
|
||||
|
||||
export const isValidURLRequest = async (url: string) => {
|
||||
try {
|
||||
const result = await fetch(url);
|
||||
return result.status === 200;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,10 +5,10 @@ import { yupResolver } from '@hookform/resolvers/yup';
|
|||
|
||||
import I18n from '../../i18n';
|
||||
import { ControlledFormTextInput } from '../../containers/TextInput';
|
||||
import { regExpUrlImage } from '../../lib/methods/helpers';
|
||||
import { regExpImageType } from '../../lib/methods/helpers';
|
||||
|
||||
const schema = yup.object().shape({
|
||||
avatarUrl: yup.string().matches(regExpUrlImage).required()
|
||||
avatarUrl: yup.string().url().matches(regExpImageType).required()
|
||||
});
|
||||
|
||||
interface ISubmit {
|
||||
|
|
Loading…
Reference in New Issue