Namburi Manikanta Namburi Manikanta - 1 year ago 47
Javascript Question

RegEx to check first two characters must be "1 (numaric)-" in 9 letter word remaing should be alphanumaric

I tried coding in such way that code was not working

var redEx = /^1-[0-9a-zA-Z]{7}/;

document.getElementById("rowidOpty").value.test(redEx)


Example: '1-5S6AW2R': in the string first letter should be numeric and
second character must be "-" and remain alpha-numeric.

Answer Source

It's regexObj.test(string) instead of string.test(regexObj).

See RegExp.prototype.test() for more information.

console.log(/^1-[0-9a-zA-Z]{7}/.test('1-5S6AW2R'))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download