1
A
回答
4
只需使用String
,並添加一些驗證,以確保輸入的是正確的類型:
COLORS = ['red', 'blue', ...];
function colorValidator (v) {
if (v.indexOf('#') == 0) {
if (v.length == 7) { // #f0f0f0
return true;
} else if (v.length == 4) { // #fff
return true;
}
}
return COLORS.indexOf(v) > -1;
};
new Schema({
color: { type: String, validate: [colorValidator, 'not a valid color'] }
});
我寫的colorValidator
迅速幫助你得到一個想法,但你可以很容易地擴展它,以獲得更復雜的顏色驗證。
相關問題
- 1. 什麼是在Swift中將UIColor轉換爲十六進制(網絡顏色)的最佳/最簡單的方法?
- 2. 在strings.xml中存儲十六進制顏色值
- 3. 爲什麼在十六進制顏色值中領先的「#FF」?
- 4. 在python中分割十六進制的最佳方法是什麼?
- 5. 存儲十六進制值
- 6. 什麼十六進制顏色代碼是「Google Plus紅色」?
- 7. 轉換顏色的十六進制值
- 8. 訂購顏色的十六進制值
- 9. 如何在數組中存儲十六進制顏色
- 10. 在MySQL中存儲十進制度的最佳方式是什麼?
- 11. 什麼是Holo.Light.DarkActionBar的默認十六進制顏色ActionBar
- 12. O_APPEND的十六進制值是什麼?
- 13. 什麼是十六進制?
- 14. 在mongoDB中存儲48位十六進制值的最有效方法是什麼?
- 15. 用十六進制顏色尋找最近的PMS顏色?
- 16. 什麼是存儲幾十列配置值的最佳方式?
- 17. 十六進制顏色在Javascript
- 18. 什麼\意思在一個CSS十六進制顏色符號?
- 19. 存儲長十六進制值
- 20. 編程中十六進制值的用法是什麼?
- 21. 爲什麼TPanel的顏色屬性在使用十六進制顏色值時顯示錯誤的顏色?
- 22. 在十六進制值中指定RGB顏色有什麼好處?
- 23. 在JS中生成隨機生成的十六進制顏色的免費十六進制顏色?
- 24. 是否可以確定指定顏色的十六進制值?
- 25. 查看任何十六進制代碼#a7a7a7的實際顏色的最快方法是什麼?
- 26. 將二進制數據存儲在數字中的最佳方法是什麼?
- 27. 在iPhone中存儲文本,字體和顏色的最佳方式是什麼?
- 28. 十三進制顏色的十六進制圖表
- 29. 確定最接近的十六進制顏色針對現有十六進制的列表值
- 30. 顯示十六進制顏色由SASS
感謝您的幫助! – Erik 2014-09-13 13:42:30