tweak on yup validation

This commit is contained in:
Reinaldo Neto 2023-01-10 21:11:04 -03:00
parent af2b2a6185
commit 2dc8a0c355
3 changed files with 4 additions and 15 deletions

View File

@ -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 // 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 '.(jpg|jpeg|png|webp|avif|gif|tiff)' + // type of the URL
'(\\?[;&a-z\\d%_.~+=-]*)?', '(\\?[;&a-z\\d%_.~+=-]*)?',
'i' // query string 'i' // query string
); );
export const isImage = (url: string) => regExpUrlImage.test(url); export const isImage = (url: string) => regExpImageType.test(url);

View File

@ -1,5 +1,3 @@
import fetch from './fetch';
export const isValidURL = (url: string): boolean => { export const isValidURL = (url: string): boolean => {
const pattern = new RegExp( const pattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol '^(https?:\\/\\/)?' + // protocol
@ -15,12 +13,3 @@ export const isValidURL = (url: string): boolean => {
// Use checkUseSsl: false only if server url starts with http:// // Use checkUseSsl: false only if server url starts with http://
export const isSsl = (url: string): boolean => !/http:\/\//.test(url); 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;
}
};

View File

@ -5,10 +5,10 @@ import { yupResolver } from '@hookform/resolvers/yup';
import I18n from '../../i18n'; import I18n from '../../i18n';
import { ControlledFormTextInput } from '../../containers/TextInput'; import { ControlledFormTextInput } from '../../containers/TextInput';
import { regExpUrlImage } from '../../lib/methods/helpers'; import { regExpImageType } from '../../lib/methods/helpers';
const schema = yup.object().shape({ const schema = yup.object().shape({
avatarUrl: yup.string().matches(regExpUrlImage).required() avatarUrl: yup.string().url().matches(regExpImageType).required()
}); });
interface ISubmit { interface ISubmit {