Function
match (dependentKey, regexp) ComputedProperty public
Module: | @ember/object |
---|
Defined in packages/@ember/object/lib/computed/computed_macros.js:394
import { match } from '@ember/object/computed';
- dependentKey
- String
- regexp
- RegExp
- returns
- ComputedProperty
- computed property which match the original value for property against a given RegExp
A computed property which matches the original value for the dependent property against a given RegExp, returning true
if the value matches the RegExp and false
if it does not.
Example:
import { set } from '@ember/object'; import { match } from '@ember/object/computed'; class User { @match('email', /^.+@.+\..+$/) hasValidEmail; } let user = new User(); user.hasValidEmail; // false set(user, 'email', ''); user.hasValidEmail; // false set(user, 'email', '[email protected]'); user.hasValidEmail; // true
Classic Class Example:
import EmberObject, { set } from '@ember/object'; import { match } from '@ember/object/computed'; let User = EmberObject.extend({ hasValidEmail: match('email', /^.+@.+\..+$/) }); let user = User.create(); user.hasValidEmail; // false set(user, 'email', ''); user.hasValidEmail; // false set(user, 'email', '[email protected]'); user.hasValidEmail; // true
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fobject%2Fcomputed/match