기본 유틸
const filterInput = (input: string, reg: RegExp) => {
const res = reg.exec(input)?.join();
return !!res ? res : "";
};
const isValidInput = (input: string, reg: RegExp) => {
return reg.test(input);
};
const isErr = patterns.some((re) => !isValidInput(text, re));
setRegError(isErr);
EMAIL
const isVaildEmail = (email: string) => {
const re = /^(([^<>()[\\]\\\\.,;:\\s@"]+(\\.[^<>()[\\]\\\\.,;:\\s@"]+)*)|(".+"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
참고
How to validate an email address in JavaScript
정규 표현식 - JavaScript | MDN
한국에서 특히 유용한 JavaScript RegEx (Regular Expression) 정리