TextField with RegExpValidator
-
I want to set a validator which allows following input into a (QtQuickControls2) TextField:
nnn/nnn
where nnn can have 2 or 3 digits and a minimum of 30 and a maximum of 300
per ex80/120
110/90RegEx is very powerful, but I'm always fighting with the syntax ;-)
can someone help with the exact syntax ?
validator: RegExpValidator{regExp: "???"}
thx
-
Do you mean the regExp syntax?
Derived from c++ probably more "\\d{2,3}/\\d{2,3}".
This is tested with the regExp example in C++. Since I do not know Qt Quick, I do not know the requirements for backslashes and their duplication.Note: this satisfies also "80/90" and "100/120". Possibly this is already enough for you.
-
@SGaist said in TextField with RegExpValidator:
Hi,
While @koahnig is correct from a C++ POV, JavaScript syntax is a bit different and IIRC RegExpValidator takes a JS regex.
Something like/\d{2,3}\/\d{2,3}/
should be enough.so to check min and max I can split the text by '/' and check both numbers
thx for helping - will try it out
-
@SGaist said in TextField with RegExpValidator:
Hi,
While @koahnig is correct from a C++ POV, JavaScript syntax is a bit different and IIRC RegExpValidator takes a JS regex.
Something like/\d{2,3}\/\d{2,3}/
should be enough.did this:
validator: RegExpValidator{regExp: "/\d{2,3}\/\d{2,3}/"}
but got an error:
Invalid property assignment: regular expression expected; use /pattern/ syntax
regexp mentioned @koahnig also don't work
-
@ekkescorner Try without quotes.
-
@p3c0 thx it works without the quotes
next question:
if I want to allow
one character of/ . ,
how must the regexp be constructed ?
reason:
on Android and iOS want to use virtual numeric keyboard where I don't have a '/'
but I can enter . on Android and , on iOS (german locale)
so I do a text.replace changing . or , into /
but using the RegExp only allowing a / as separator I cannot enter . or ,thx again
-