2016-10-24 45 views
0

如何爲無效輸入自定義錯誤消息?如何爲無效輸入自定義錯誤消息?

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "type": "object", 
    "properties": { 
    "username": { 
     "type": "string", 
     "pattern": "^[A-Za-z0-9-_.]+$", 
     "minLength": 3 
    }, 
    "password": { 
     "type": "string", 
     "minLength": 8, 
     "pattern": "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d\\W]$" 
    } 
    }, 
    "required": [ 
    "username", 
    "password" 
    ], 
    "errors": [ 
    { 
     "property": "username", 
     "message": "min 3 characters, do not use spaces or special characters" 
    } 
    ] 
} 

例如,如果用戶名的輸入不是所需的最小長度或不滿足正則表達式模式,顯示一個自定義消息min 3 characters, do not use spaces or special characters

回答

1

定製錯誤消息不被支持。但是,有一些討論會在下一個版本的JSON模式中添加這樣的功能。