filter([regex_filter])

Class: TextField.

Description:

Sets or gets a text input filter regular expression that filters the input of text to allow only text that matches filter.

The filter must match the entire text of the field, not just a single character.

NOTE: When setting text to TextField that doesn't match this filter, the text will not be set and previous text will remain in the text field.

Parameters:

Name Type Description

[regex_filter]

string

Regular expression filter string. Set to empty string to remove existing filter.

Returns:

When setting a filter, this TextField component is returned. When called without arguments, returns the current filter string.

Type: string | TextField

Examples:

// Allow only digits
textfield.filter("^\\d*$");
// Allow U.S. phone numbers in format 123-456-7890
textfield.filter("^\\d{3}-\\d{3}-\\d{4}$");

// Allow only characters valid for email address
textfield.filter([A-Za-z0-9\.\_\%\+\-
// Allow basic email addresses (accepts partial email)
textfield.filter("^[a-zA-Z0-9.\\_\\%\\+\\-]+(@([a-zA-Z0-9-]*(\\.[a-zA-Z0-9-]*)*(\\.[a-zA-Z]*)?))?$");
// Allow basic email addresses (email cannot be typed one character at at time, only pasted in full)
textfield.filter("^[A-Za-z0-9\\.\\_\\%\\+\\-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$");
// Remove filter
textfield.filter("");