Q:

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

mobno :
    {
      type : Number,
      required : true,
      min : 10,
      max : 10,
      unique : true
    },
When I use this current schema i get validation errors on trying to insert new data. I know that this method of setting digit restriction is incorrect but I'm unable to find anything online about it. Thanks in advance for the help!

A:

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

Source: http://mongoosejs.com/docs/validation.html

