This commit is contained in:
aisen 2020-12-05 03:55:41 -08:00 committed by GitHub
commit 4ba7f8d58d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -33,6 +33,8 @@ export function validURL(url) {
* @returns {Boolean}
*/
export function validLowerCase(str) {
// https://www.coder.work/article/1041931
if (str === undefined || str === null) return false
const reg = /^[a-z]+$/
return reg.test(str)
}
@ -42,6 +44,8 @@ export function validLowerCase(str) {
* @returns {Boolean}
*/
export function validUpperCase(str) {
// https://www.coder.work/article/1041931
if (str === undefined || str === null) return false
const reg = /^[A-Z]+$/
return reg.test(str)
}

View File

@ -14,11 +14,13 @@ describe('Utils:validate', () => {
expect(validLowerCase('abc')).toBe(true)
expect(validLowerCase('Abc')).toBe(false)
expect(validLowerCase('123abc')).toBe(false)
expect(validLowerCase()).toBe(false)
})
it('validUpperCase', () => {
expect(validUpperCase('ABC')).toBe(true)
expect(validUpperCase('Abc')).toBe(false)
expect(validUpperCase('123ABC')).toBe(false)
expect(validUpperCase()).toBe(false)
})
it('validAlphabets', () => {
expect(validAlphabets('ABC')).toBe(true)