powmedia / backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
MIT License
2.17k stars 413 forks source link

Allow string input on regexp validator #300

Closed baseprime closed 10 years ago

baseprime commented 11 years ago

This would allow RegExp validator parse a string instead of requiring the value to be an instance of RegExp. Particularly useful if the schema is transmitted as a JSON object over AJAX for example.

// GET /api/schema
{
    error : false,
    code : 200,
    response : {
        id : {
            type : 'Number',
            title : 'ID'
        },
        name : {
            type : 'Text',
            title : 'Name',
            validators : [
                { type : 'regexp', message : 'Not a valid name!', regexp : '^[a-zA-Z]+$' }
            ]
        }
    }
}
baseprime commented 11 years ago

Anyone? This is a one-line change and would extend validator functionality tremendously.

powmedia commented 11 years ago

Could you include a test for this and I'll merge it in? Thanks

baseprime commented 10 years ago

@powmedia Sorry for the late reply. I've included tests and also added options.flags when creating the RegExp object from a string.