In my template driven form the textarea is required based on a condtion. I would also like the pattern to be conditional. I tried this syntax based on a question from angular 1.x but it doesn't seem to work. - pattern=" condition ? '.*[^ ].*' : ''" I also tried - pattern="condition ? (\s*[^\s]+\s*)+ : .*". is this possible with the later versions of Angular? Here is my stack blitz: https://stackblitz.com/edit/conditionalpattern
Conditional pattern to be used along with required Angular7/8
2.4k Views Asked by Flash At
2
There are 2 best solutions below
Related Questions in HTML
- Delay in loading Html Page(WebView) from assets folder in real android device
- Why does a function show up as not defined
- CSS Class is not applying to element (border width,color,and style attributes)
- How to sort these using Javascript or Jquery Most effectively
- how to fill out the table with next values in array with one button
- Automatically closing tags in form input?
- Positioning child at bottom of parent with scroll
- Remove added set of rows
- Website zoomed out on Android default browser
- Twitter Bootstrap horizontal form elements on a line
- http://sigmajs.org/ les mis tutorial - why are my canvases 0 height?
- My navbar is not expanding after collapse
- when a checkbox is checked how to display a different hidden element using javascript
- Gaps Vertically Using Dividers
- Svg containers not positioning properly
Related Questions in ANGULAR
- Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?
- Module '"angular2/angular2"' has no exported member 'For'
- import syntax in typescript creating another js file in visual studio
- Separate ts file for imports
- How to use an AngularJS 2 component multiple times in the same page?
- injectables not working in angular 2.0 latest build 26
- Does angular2 bootstrap have a way to dynamically target elements like it does in angular 1.x
- Import {} from location is not found in VS Code using TypeScript and Angular 2
- Angular 2/Typescript: require not found
- ng-switch in Angular2
- Angular 2 import issue: "Zone already exported on window the object!"
- How to make FileReader work with Angular2?
- Writing the most basic Unit test in Angular 2?
- Angular2: Creating child components programmatically
- AngularJS - TypeError: Cannot read property 'canonicalUrl' of undefined
Related Questions in VALIDATION
- Escape dot in jquery validate plugin
- PHP form validation: Where to plop the code
- i want to create a service that does the login functionality?
- Stray start tag head, Element style not allowed as child of element body in this context. (Suppressing further errors from this subtree.)
- Html File Input on Chrome for Android missing extension and mime type
- javascript check input fields are not blank and check input field length?
- Symfony 2 form - date widget and validator
- Bean Validation message interpolation with array constraint parameter used as variable in message
- Bash regular expression execution hangs on long expressions
- Accessing the main object in a javax.validation.ConstraintValidator
- RAILS: date_select validation
- How can I define items of an array in a form in AngularJS
- Validation DataGridView Windows Forms
- How to handle multiple if statements PHP
- Restrict comma in asp.net textbox
Related Questions in NG-PATTERN
- Custom notPattern directive like ngPattern, but checking whether a RegExp does not match
- Validate A-Z0-9 has maxlength 10, but allow user to enter spaces (but skip spaces in maximum)
- Regex to validate that the first letter of a word in input field is not a special character
- how to specify a decimal (dd,dd) with type text usign ng-pattern
- Regex with min 8 digits, 20 characters
- AngularJS : email or phone number validation
- ng-pattern that allows decimal ratios
- ng-class not setting class right after conditions are met
- Pattern that restricts user to enter special characters for first character
- ng-pattern for input text
- AngularJS ng-pattern with or within textbox
- Using ng-pattern with ng-model parsing/formatting
- How to disallow space using ng-pattern
- ng-pattern for PCRE
- Ng-Pattern performance issue with multiline regex
Related Questions in NG-REQUIRED
- ng-Required for Checkbox
- NG-Required not working on search input fields
- md-select and required doesn't detect empty value
- required directive not working on select tag in Angular
- Angularjs - ng-invalid not working correctly on select element inside ng-repeat table
- Angular2 <form> input validation
- Conditional pattern to be used along with required Angular7/8
- apply ng-required if another element is selected
- angularjs ng-repeat input fields ng-required not working
- Angular ng-required
- myForm.$valid returns true even though required feld is empty
- AngularJS - problems with ngRequired and conditional undefined
- How can I validate my input only if my field is not disabled
- ng-pattern becomes invalid when ng-required value changes
- AngularJS ngRequired custom directive
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I think if you want to pass an expression, you should wrap pattern in square brackets. But more importantly, you cannot use the attribute
patternin the tagtextarea, becausepatternis not an allowed attribute fortextarea.As described in MDN Web Docs,
So in your case I would either use an
inputor consider using aCustomValidator. If you use an input, make sure to wrap the expression in brackets:Here's a tiny stackblitz with a working example of an input field.