input.js
js
const REGEXP_KOREAN_ALPHABET = '[a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ]{1,}'
const REGEXP_KOREAN_ALPHABET_NUMBER = '[a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ0-9 _]{1,}'
const REGEXP_KOREAN_ALPHABET_WHITESPACE = '[a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ ]{1,}'
const REGEXP_NUMBER = '[0-9]{0,}'
const REGEXP = {
// 한글, 영문, 숫자, 공백허용, 특수기호 불가능
KOREAN_ALPHABET_NUMBER_WHITESPACE: /[가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z0-9\s]/g,
// 한글, 영문, 숫자, 공백허용, 일부 특수기호 허용 (즉, 이모지 불가능)
ALL_AND_LIMITED_SPECIAL_CHARACTERS: /[가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z0-9\s`₩~!@#$%^&*()_+\-=[\]{}<>,.?/|\\'":;]/g,
// 숫자만 허용
NUMBER: /[0-9]/g,
};
date.js
js
const [year, month, date] = birthDateStr
.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3')
.split('-')
'2018.02.14'
.replace(/\d{4}.(\d{2}).(\d{2})/, '$1/$2')
.replace(/^0/, '') // 2/14
'2018.12.14'
.replace(/\d{4}.(\d{2}).(\d{2})/, '$1/$2')
.replace(/^0/, '') // 12/14
url.js
js
const URL_REGEXP = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
const urlToAnchor = (url) => {
return url.replace(URL_REGEXP, '<a href="$&">$&</a>')
}
special-char.js
js
const escapeSpecialChar = str => str.replace(
/[.*+?^${}()|[\]\\]/g,
'\\$&'
);