Node.js Editor - Regex Validation possible

Node.js Editor - Regex Validation possible

CapamaniaCapamania Posts: 233Questions: 81Answers: 5
edited November 2018 in Editor

I want to regex validate some input fields with editor node.js. Is this possible? For instance is this example working?

new Field("name")
    .validator((val, data, host) => {
        if(val === null){
            return true;
        } else {
            return val.match("/^[a-zA-Z ]+$/") 
                ? 'Not valid!' 
                : true;
        }
    })

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    I don't think you want the regex expression in quotes. I believe it should look like this: return val.match(/^[a-zA-Z ]+$/).

    Kevin

This discussion has been closed.