node.js - 有没有办法使用 express-validator 检查第一个字符是否是字母?
问题描述
case 'user_name': { return [ check( 'content.data.userName', '用户名需要至少一个字母' ) // .matches('(?=. [az])(?=. [0-9]) ') .exists() .trim() .bail() .isLength({ min: 6 }) .withMessage('用户名必须至少有6个字符') .isLowercase() .withMessage('必须全是小写字母')
case 'user_name': {
return [
check(
'content.data.userName',
'username need atleast one alphabet'
)
// .matches('(?=.*[a-z])(?=.*[0-9])')
.exists()
.trim()
.bail()
.isLength({ min: 6 })
.withMessage('User Name must be atleast have 6 characters')
.isLowercase()
.withMessage('Must be all small letters')
解决方案
This regular expression helps you to check the first character is alphabet or not.
^[a-zA-Z][\w\s-]+
第一个字符只能是 a-zA-Z
不允许使用“空格”和“连字符(-)”以外的特殊字符
.matches(/^[a-zA-Z][\w\s-]+/)
希望有效,谢谢!
推荐阅读
- facebook - Facebook API – 如何获取页面范围的用户 ID(ids_for_pages 为空)?
- powershell - 从 PowerShell 执行 .exe 文件并等待所有子进程完成
- c - 如何针对矩阵矩阵乘法内核优化由于 Haswell 中的 L1D 缓存绑定代码导致的管道停顿?
- python - 重写的 QGraphicsView keyPressEvent 从焦点 QGraphicsWidgets 窃取事件
- python - 在 csv 文件中搜索名称并返回整行
- scala - 可以使用反射或类似方法识别/使用 Scala 宏吗?
- go - 戈朗;难以理解作为接收器的功能
- javascript - Javascript 树搜索算法,它返回包含找到的术语及其父项的树的子集
- node.js - docker-compose up 未正确运行应用程序
- node.js - 在 MongoDB 文档字段中添加附件