I'm trying to create a national document validator that accepts numbers and letters or just an 11-character JavaScript limit number.
The problem is with regex creation.
Follow the code:
var documento = 'abc123-$/';
alert(documento.replace(/^[A-Za-z0-9]{0,5}\d+[A-Za-z0-9]{0,6}$g/,"")); // resultado deveria ser: abc123
var documento = 'abcdef-$/';
alert(documento.replace(/^[A-Za-z0-9]{0,5}\d+[A-Za-z0-9]{0,6}$g/,"")); // resultado deveria ser vazio porque deve conter pelo menos 1 número
Here's an example in JSFiddle: JSFiddle