I am trying to validate a simple textfield that should accept either:
the numbers 0-100 OR the letters AF
To clarify, it is for a teacher grading assignments, so only the scores of 0-100 and AF are accepted (no special/non-alphanumeric characters etc).
I just can't seem to wrap my head around reg exp and the Sencha Touch matcher. I have seen the other posts but they are not quite applicable to my question. Thanks.
My model:
Ext.define('App.model.EnterGradesModel',{
extend: 'Ext.data.Model',
alias: 'model.User',
config: {
fields: [
{
grade: 'grade'
}
],
validations: [
{
type: 'format',
field: 'grade',
matcher: //This is where I need the help ----- ,
message: 'Grade should be 0-100 or A-F'
}
]
}
});
Handler in my view:
{
xtype: 'button',
width: 100,
text: "Save",
id: "saveMyGradeButton",
action: 'saveMyGrade',
handler : function() {
var model = Ext.create('App.model.EnterGradesModel', this.up('formpanel').getValues());
var errors = model.validate();
console.log(model);
if (errors.isValid()){
// Validation successful - fire grade event in controller
this.fireEvent('saveMyGrade', this);
} else {
// Validation failed
var data="";
console.log(data);
errors.each(function (item, index, length) {
data = data + '| '+ item.getField() + ' - ' + item.getMessage() + ' |';
});
Ext.Msg.alert("oops.", data);
}
}
}
This expression will validate one of the following conditions is true
^(?:100|[1-9]\\d|\\d|[AF])$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.