[英]there is a "Alphanumeric" option for adonis js5 Validator?
Hi everybody i end of to read the documentation of adonis js for to use "validation rules" but i dont see a option for to validate a "alphanumeric" value(in adonisjs 4.1 this exist but i try to migrate to adonis 5), i have the way of to make this rule but before i need to question ¿Really there not is a alphanumeric validation in validation rules or i need to read the guide again?大家好,我最后阅读了 adonis js 的文档以使用“验证规则”,但我没有看到验证“字母数字”值的选项(在 adonisjs 4.1 中存在,但我尝试迁移到 adonis 5),我有办法制定这条规则,但在我需要质疑之前¿真的没有验证规则中的字母数字验证,或者我需要再次阅读指南? and ¿there is some platform for ican to send my custom validation rules?
和 ¿ 有一些平台可以让 ican 发送我的自定义验证规则? Thanks for the answers
感谢您的回答
Use the regex
helper rule to implement an alphanumeric rule.使用
regex
辅助规则来实现字母数字规则。
{
username: schema.string({}, [
rules.regex(/^[a-zA-Z0-9]+$/)
])
}
This will allow these:这将允许这些:
username10 // --> OK
username // --> OK
Username10 // --> OK
while disallowing these:同时禁止这些:
user_name // --> BAD
user-name10 // --> BAD
USER@name10 // --> BAD
Now there is a rule called alpha
, you can check it out here: https://preview.adonisjs.com/guides/validator/rules#rulesalpha现在有一个叫做
alpha
的规则,你可以在这里查看: https : //preview.adonisjs.com/guides/validator/rules#rulesalpha
Or just create a Custom Rule or regex.或者只是创建一个自定义规则或正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.