Node.js Editor - Regex Validation possible

Node.js Editor - Regex Validation possible

CapamaniaCapamania Posts: 229Questions: 79Answers: 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: 20,302Questions: 26Answers: 4,769

    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.