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'))
```
If you want to validate the input matches exactly one numeric, one dash and 7 alphanumerics exactly, use this:

```
/^[0-9]-[a-zA-Z-0-9]{7}$/;

```

or if the first can be only the numeral 1:

```
/^1-[a-zA-Z-0-9]{7}$/;

```

If you want to search for all occurrences of this pattern in a string that contains a lot of text:

```
/(^|\s)[0-9]-[a-zA-Z-0-9]{7}(\s|$)/g;

```

```js
var restrictivePattern = /^[0-9]-[a-zA-Z-0-9]{7}$/;
var loosePattern = /(^|\s)[0-9]-[a-zA-Z-0-9]{7}(\s|$)/g;
var str = '1-A78Z2TE';
var longStr = 'We have 2 different codes 1-AYRJ3F4 and 4-23RJ3F4';

console.log("Validation of string to match pattern: ", str.match(restrictivePattern))
console.log("Multiple matches in string: ", longStr.match(loosePattern))
```