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
- What is JSONP, and why was it created?
- React – uncaught TypeError: Cannot read property ‘setState’ of undefined
- Add swipe left/right to web page, but use default swipe up/down
- Uncaught TypeError : cannot read property ‘replace’ of undefined In Grid
- character counter – backspace doesn’t reflect on characters remaining
- How does the double exclamation (!!) work in javascript?
- Add days to JavaScript Date
- Make Axios send cookies in its requests automatically
- Call python function from JS
- How to add onload event to a div element
- Access Control Origin Header error using Axios
- Structs in Javascript
- Refused to execute script, strict MIME type checking is enabled?
- setInterval with loop time
- How to disable auto-start of “Node.js: Server-side JavaScript” when using Adobe Dreamweaver?
- How should I initialize jQuery?
- WordPress Bootstrap Handburger Menu Wont Open
- Animations are not being triggered on Scroll
- Preserve Javascript Through Customizer Preview Navigation
- JavaScript in WordPress Customizer
- How to use div -ids in url to jump to specific post…Is trailing slash the culprit?
- How Can I Add OnClick Event To A Specific WordPress Menu Link
- What’s the most efficient way to include this javascript in only a single post?
- How to add customizer control via javascript ( wp.customizer.control.add )
- How to generate the COOKIEHASH from JavaScript
- Problem after upgrade to 3.6.1
- When adding google tag script in website, functionality not working
- How should I identify the inline javascript that is the dependent of a wp_enqueue_script?