如何限制 mobno 字段中的位数(例如 10)?

How to set limit on the number of digits in the mobno field(eg-10)?

手机号码: { 类型:数字, 要求:真实, 分钟:10, 最大值:10, 独特的:真实的 }, 当我使用当前模式时,我在尝试插入新数据时遇到验证错误。我知道这种设置数字限制的方法是不正确的,但我无法在网上找到任何相关信息。在此先感谢您的帮助!

试试这个:

mobno:{
       type:String, 
       unique:true,
       validate: {
       validator: function(v) {
         return /^([0-9]{10}$)/.test(v);
       }},
       required: true
       }

来源:http://mongoosejs.com/docs/validation.html