Skip to content

Commit

Permalink
Merge pull request #43 from ershisi214/main
Browse files Browse the repository at this point in the history
feat: #42 判断字符串是否是十六进制的颜色值
  • Loading branch information
MaleWeb authored Jul 25, 2022
2 parents 4f75001 + 6629fbc commit e32346a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/guide/Regex.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,14 @@
* @example if (isUrl(str)) { doSomething }
*/
```
## isColor
判断字符串是否是十六进制的颜色值
```typescript
/**
* @func isColor
* @desc 判断字符串是否是十六进制的颜色值
* @param {string} value 需要判断的数据
* @returns {boolean} 校验是否是十六进制的颜色值
* @example if (isColor(str)) { doSomething }
*/
```
11 changes: 11 additions & 0 deletions src/regex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@ export const isUrl = (str: string): boolean => {
const reg = /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/;
return reg.test(str);
}

/**
* @func isColor
* @desc 判断字符串是否是十六进制的颜色值
* @param {string} value 需要判断的数据
* @returns {boolean} 校验是否是十六进制的颜色值
* @example if (isColor(str)) { doSomething }
*/
export const isColor = function(value: string): boolean {
return /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(value);
}

0 comments on commit e32346a

Please sign in to comment.