mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
83 lines
2.8 KiB
YAML
83 lines
2.8 KiB
YAML
# Copyright 2020-2021 Lowdefy, Inc
|
||
|
||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||
# you may not use this file except in compliance with the License.
|
||
# You may obtain a copy of the License at
|
||
|
||
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
||
# Unless required by applicable law or agreed to in writing, software
|
||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
# See the License for the specific language governing permissions and
|
||
# limitations under the License.
|
||
|
||
_ref:
|
||
path: templates/operators.yaml.njk
|
||
transformer: templates/operatorsMethodTransformer.js
|
||
vars:
|
||
pageId: _regex
|
||
pageTitle: _regex
|
||
types: |
|
||
```
|
||
(pattern: string): boolean
|
||
(arguments: {
|
||
pattern: string,
|
||
on?: string,
|
||
key?: string,
|
||
flags?: string
|
||
}): boolean
|
||
```
|
||
description: |
|
||
The `_regex` operator performs a regex test on a string, and returns `true` if there is a match.
|
||
|
||
The regex operator has shorthand argument definitions that can be used on web client.
|
||
arguments: |
|
||
###### object
|
||
- `pattern: string`: __Required__ - The regular expression pattern to test.
|
||
- `on: string`: The string to test the value on. One of `on` or `key` must be specified unless the operator is used in an input block.
|
||
- `key: string`: The key of a value in `state` to test. One of `on` or `key` must be specified unless the operator is used in an input block.
|
||
- `flags: string`: The regex flags to use. The default value is `"gm"`.
|
||
|
||
###### string
|
||
The regular expression pattern to test. The string shorthand can only be used in an input block, and the tested value will be the block's value.
|
||
examples: |
|
||
###### Check if a username is valid (Alphanumeric string that may include _ and – having a length of 3 to 16 characters):
|
||
```yaml
|
||
_regex:
|
||
pattern: ^[a-z0-9_-]{3,16}$
|
||
on:
|
||
_state: username_input
|
||
```
|
||
Returns: `true` if matched else `false`.
|
||
|
||
###### Using the key of the value in `state`:
|
||
```yaml
|
||
_regex:
|
||
pattern: ^[a-z0-9_-]{3,16}$
|
||
key: username_input
|
||
```
|
||
Returns: `true` if matched else `false`.
|
||
|
||
###### Using the value of the block in which the operator is evaluated:
|
||
```yaml
|
||
id: username_input
|
||
type: TextInput
|
||
validation:
|
||
- message: Invalid username.
|
||
status: error
|
||
pass:
|
||
_regex: ^[a-z0-9_-]{3,16}$
|
||
```
|
||
Returns: `true` if matched else `false`.
|
||
|
||
###### Case insensitive match:
|
||
```yaml
|
||
_regex:
|
||
pattern: ^[a-z0-9_-]{3,16}$
|
||
on:
|
||
_state: username_input
|
||
flags: 'gmi'
|
||
```
|
||
Returns: `true` if matched else `false`.
|