2014-10-09 47 views
2

我是mongoDB和mongoose的新手,實際上我是Javascript新手。由於這個原因,我不確定我應該如何去清理我的數據。是否有任何Mongoose驗證庫?

我想知道是否有任何庫自定義驗證功能,至少應該注意一些通用的危險,應該注意的。如果它已經有了常用的驗證,例如電子郵件或字符長度,它也會很好。

+2

http://plugins.mongoosejs.com/ – JohnnyHK 2014-10-09 04:14:42

+0

哦哇,這是好的,但它並沒有真正回答我應該尋找什麼貓鼬消毒時防止惡意注射查詢。 – grasshopper 2014-10-09 04:42:01

回答

-1

嗨,有很多用於貓鼬模式驗證的庫。下面列出了一些庫。 https://github.com/leepowellcouk/mongoose-validator

https://github.com/SamVerschueren/node-mongoose-validator

都是好的庫,用於貓鼬validation..Also貓鼬進行驗證提供自定義邏輯。

更多如果你想創建自定義邏輯,然後https://github.com/chriso/validator.js對你有幫助。

的電子郵件驗證我用這個

const emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ 

email: { 
    type: String, 
    trim: true, 
    unique: true, 
    required: 'Email address is required', 
    validate: { 
     validator: (email)=> { 
     return emailRegex.test(email) 
     }, 
     message: '{VALUE} is not a valid email' 
    }, 
    match: [emailRegex, 'Please fill a valid email address'] 

    } 
相關問題