I want to allow any letters or digits and if used, allow #
only at the beginning with only one occurence something like #{1}
. And keep those restrictions that I already have in the expression for characters ^<>@.\/()
.
Here is my Regex:
/^[#?a-zA-z0-9][^<>@.\/()]+/g
Some use cases I want this regex expression to pass:
##msidfipds - fail (2 of #)
fdsfsdfd#1m - fail (# not 1st character)
vcvxcvxcvxc - pass
#fdfdsfsdfs - pass
Use case for TextField
widget.
TextField(
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp(r'^#?[a-zA-Z0-9][^#<>@.\/()]*$')),
],
autofocus: true,
enableInteractiveSelection: true,
keyboardType: TextInputType.text,
decoration: InputDecoration(
fillColor: Colors.transparent,
border: InputBorder.none,
hintText: 'Search',
),
textAlign: TextAlign.center,
style: TextFieldStyle,
),