Question: 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: 
It's `regexObj.test(string)` instead of `string.test(regexObj)`.

See [`RegExp.prototype.test()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test) for more information.

```js
console.log(/^1-[0-9a-zA-Z]{7}/.test('1-5S6AW2R'))
```
```js
pattern = /^[0-9]-(\w+)/g;

console.log('1-5S6AW2R'.match(pattern))
```

Try this pattern `^[0-9]-(\w+)`

**[Demo Regex](https://regex101.com/r/8j4UXP/2)**