I think you want to test
your RegExp in TypeScript, so you have to do like this:
var trigger = "2", regexp = new RegExp('^[1-9]\d{0,2}$'), test = regexp.test(trigger); alert(test + ""); // will display true
You should read MDN Reference – RegExp, the RegExp
object accepts two parameters pattern
and flags
which is nullable(can be omitted/undefined). To test your regex you have to use the .test()
method, not passing the string you want to test inside the declaration of your RegExp!
Why test + ""
? Because alert()
in TS accepts a string as argument, it is better to write it this way. You can try the full code here.
Related Posts:
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- ES6 Map in Typescript
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Javascript split regex question
- How to define type for a function callback (as any function type, not universal any) used in a method parameter
- TypeScript foreach return [duplicate]
- TypeScript React.FC
confusion - 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
- How to perform string interpolation in TypeScript?
- Angular: mat-form-field must contain a MatFormFieldControl
- (change) vs (ngModelChange) in angular
- Typescript : Property does not exist on type ‘object’
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- Escaping Discord subset of markdown
- How to test valid UUID/GUID?
- Angular ForEach in Angular4/Typescript?
- Regular expression : match either of two conditions?
- Angular4 – No value accessor for form control
- Possible to extend types in Typescript?
- No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’
- How do you format a Date/Time in TypeScript?
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- What is ViewChild in Angular2?
- How do I check whether an array contains a string in TypeScript?
- Converting any string into camel case
- I want to remove double quotes from a String
- Uncaught ReferenceError: define is not defined typescript
- Regular expression for removing whitespaces
- Javascript Regular Expression Remove Spaces
- How can I extract a number from a string in JavaScript?
- String.Format not work in TypeScript
- declaration or statement expected javascript/typescript
- TypeError: Class extends value undefined is not a function or null
- Can’t perform a React state update on an unmounted component
- Remove not alphanumeric characters from string
- Extract hostname name from string
- Difference between ?:, ?! and ?=
- Angular 4 setTimeout() with variable delay and wait
- 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
- Jquery Value match Regex
- RegEx: How can I match all numbers greater than 49?
- Regular expression to validate US phone numbers?
- How do I download a file with Angular2 or greater
- javascript includes() case insensitive
- RegEx for Javascript to allow only alphanumeric
- typescript – cloning object
- Angular 2 Sort table columns
- How do I install Angular 2 using NPM?
- Check user logged in with JS
- Jest spy on functionality
- Use a JSON array with objects with javascript
- Toggle show/hide on click with jQuery
- How do you check if a variable is an array in JavaScript?
- Understanding React-Redux and mapStateToProps()
- What is the meaning of == $0 that is shown in inspect element of google chrome for the selected element [duplicate]
- 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
- Send POST data using XMLHttpRequest
- querySelector vs. getElementById
- Google weather widget on my website
- How to generate a simple popup using jQuery
- How to convert an Object {} to an Array [] of key-value pairs in JavaScript
- Javascript versioning to avoid caching, difference in these practices?
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- How to implement authenticated routes in React Router 4?
- How to create a JQuery Clock / Timer
- Access Control Request Headers, is added to header in AJAX request with jQuery
- React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
- How to check if function exists in JavaScript?
- getBoundingClientRect is not a function
- Jquery button click() function is not working
- Make iframe automatically adjust height according to the contents without using scrollbar?
- How do I check whether a checkbox is checked in jQuery?
- Failed to find a valid digest in the ‘integrity’ attribute for resource on a deployed emberjs application
- Cannot read property ‘getHostNode’ of null
- Eslint: How to disable “unexpected console statement” in Node.js?
- Get the Highlighted/Selected text
- Video auto play is not working in Safari and Chrome desktop browser
- Uncaught ReferenceError: ga is not defined
- Getting or changing CSS class property with Javascript using DOM style
- How to close a window using jQuery
- Javascript- Multiplying 2 numbers and return number
- What does the $() function do in JavaScript?
- WP Rest API – How to get featured image
- How to only enqueue block javascript on the frontend when its needed [duplicate]
- How to replace a javascript select box onchange event to a form submit action?
- How to Add Javascript Only When a Function Exists?
- TypeError: window.tinyMCE.execInstanceCommand is not a function
- event/callback on block update?
- Gutenberg consume wp-json data and reflect in frontend the content
- Removing admin javascript
- Can I get the user name in JavaScript?
- Landing function through URL
- How can I look at/edit what’s being sent to post.php when I hit the publish/update button?