In your regex, the two alternative branches are anchored separately:
(^([a-zA-Z]){2}([0-9]){6})
– 2 letters and 6 digits at the start of the string|
– or([0-9]*)?$
– optional zero or more digits at the end of the string
You need to adjust the boundaries of the group:
data-ng-pattern="/^([a-zA-Z]{2}[0-9]{6}|[0-9]{8})?$/" ^ ^^^^
See the regex demo.
Now, the pattern will match:
^
– start of string(
– start of the grouping:[a-zA-Z]{2}[0-9]{6}
– 2 letters and 6 digits|
– or[0-9]{8}
– 8 digits
)?
– end of the grouping and?
quantifier makes it match 1 or 0 times (optional)$
– end of string.
Related Posts:
- Javascript split regex question
- How to get all place details from a Place Details Request using Google Places API Web Service?
- SyntaxError: Unexpected token o in JSON at position 1
- SyntaxError: Unexpected token o in JSON at position 1
- SyntaxError: Unexpected token o in JSON at position 1
- SyntaxError: Unexpected token o in JSON at position 1
- What is a good regular expression to match a URL? [duplicate]
- What is a good regular expression to match a URL? [duplicate]
- Is there a difference between /\s/g and /\s+/g?
- RegEx Ignore Case
- JavaScript replace/regex
- AngularJS- Login and Authentication in each route and controller
- TypeError: Cannot read property ‘then’ of undefined
- How to Create simple drag and Drop in angularjs
- Working with $scope.$emit and $scope.$on
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- In angularjs we are having ng-disabled directive, why ng-enabled directive is not provided by the framework as we are having ng-show and ng-hide
- Escaping Discord subset of markdown
- How to test valid UUID/GUID?
- SyntaxError: Unexpected token o in JSON at position 1
- AngularJS : Factory and Service?
- Give a value to an ng-model=”searchText” input based on list item clicked in Angular JS
- TypeError: Cannot read property ‘get’ of undefined on AngularJS
- RegExp in TypeScript
- Blocked script execution in because the document’s frame is sandboxed – Angular application
- Angular JS Uncaught Error: [$injector:modulerr]
- Use of $parse in angular js
- How to set the id attribute of a HTML element dynamically with angularjs (1.x)?
- Using $setValidity inside a Controller
- How can I group data with an Angular filter?
- Converting any string into camel case
- I want to remove double quotes from a String
- Regular expression for removing whitespaces
- Error: ENOENT: no such file or directory, stat ‘/public/main.html’ at Error (native)
- Javascript Regular Expression Remove Spaces
- Disable Chrome strict MIME type checking
- How can I extract a number from a string in JavaScript?
- Angularjs: Error: [ng:areq] Argument ‘HomeController’ is not a function, got undefined
- Error: [ng:areq] from angular controller
- SyntaxError: expected expression, got ‘<'
- Understanding the ngRepeat ‘track by’ expression
- How to pass parameters using ui-sref in ui-router to controller
- What does ngf-select do and why is it needed for form validation?
- Remove not alphanumeric characters from string
- why angularjs ng-repeat not working
- Extract hostname name from string
- How to connect signalR from angularJs
- Array Mapping in AngularJs
- Difference between ?:, ?! and ?=
- AngularJS errors: Blocked loading resource from url not allowed by $sceDelegate policy
- How do you serve a file for download with AngularJS or Javascript?
- Failed to execute ‘postMessage’ on ‘DOMWindow’: https://www.youtube.com !== http://localhost:9000
- Remove all special characters with RegExp
- How do you use a variable in a regular expression?
- How to count string occurrence in string?
- Regular Expression to reformat a US phone number in Javascript
- How to redirect to another page using AngularJS?
- Jquery Value match Regex
- RegEx: How can I match all numbers greater than 49?
- Why is this simple AngularJS ng-show not working?
- Regular expression to validate US phone numbers?
- How to enable CORS in AngularJs
- javascript includes() case insensitive
- RegEx for Javascript to allow only alphanumeric
- How do I bind to list of checkbox values with AngularJS?
- parsing JSONP $http.jsonp() response in angular.js
- AngularJS POST Fails: Response for preflight has invalid HTTP status code 404
- What is the cause for “angular is not defined”
- $http.get(…).success is not a function
- Unexpected token < in first line of HTML
- ngular is automatically adding ‘ng-invalid’ class on ‘required’ fields
- Check user logged in with JS
- How can I generate a rainbow circle using HTML5 canvas?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- What does “javascript:void(0)” mean?
- For-each over an array in JavaScript
- How to delete a cookie?
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- How do you use the ? : (conditional) operator in JavaScript?
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- are there dictionaries in javascript like python?
- How to do associative array/hashing in JavaScript
- How to make a discord bot create an invite for every server it joins?
- ES6 Map in Typescript
- addEventListener vs onclick
- “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6
- How do I check if an array includes a value in JavaScript?
- JavaScript document.getElementById().value logs empty value
- How do I color a hexagonal grid such that it doesn’t have neighbors of the same color?
- How to format a JavaScript date
- What does href expression do?
- map function for objects (instead of arrays)
- Wait 5 seconds before executing next line
- Failed to load resource: the server responded with a status of 404 (Not Found)
- How to check whether a string contains a substring in JavaScript?
- Check if a string has a certain piece of text [duplicate]
- Kadane’s algorithm explained
- What is console.log?
- Dynamically creating charts of each row in an HTML table with chart.js
- Failed to load resource: the server responded with a status of 404 (Not Found)