Skip to content

DrEhsan/persian-mongoose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

persian-mongoose

persian localization and validation for mongoose schemas

for persian validation we use persianize as validators.

Installation

npm install persian-mongoose

Persian Validation

A set of validation for persian and Iran usages

Function Description
isMobile check if string is following iran's mobile number formats
isCardNumber check if string is a real iran bank card number
isPhone check if string is iran's phone number format
isPostalCode check if string following iran's postal code's format
isSheba check if string is real sheba number
isMelliCode check if string is real melli code

Example :

var mySchema = new mongoose.Schema({
    phone_number : {
      type : String,
      validate: [
        { validator: persianMongoose.isMobile, msg: 'phone number is incorrect'}
      ]
    }
});

Convertors

removeArabicChars

This converts arabic alphabet characters to persian characters

Example (convert arabic chars to persian) :

//Input : فارسي   -> Ouput : فارسی

Schema.plugin(persianMongoose.removeArabicChars,
{
    removeArabicChars:
    {
        fields : ['name']
    }
});

Complete Usage

var mySchema = new mongoose.Schema({
    name: {type: String}
});

mySchema.plugin(persianMongoose.removeArabicChars,
{
    removeArabicChars:
    {
        fields : ['name']
    }
});

var myModel = mongoose.model('myModel', mySchema);

var newName = new myModel({ name : 'علي' });

newName.save(function (err) {

  if (err)
    console.log(err)

  // saved!
});
// will save { name : 'علی' }

About

persian localization and validation for mongoose schemas

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published