Hi everyone !
I would like setup a type of string with a regex constraint:
~/[A-Z]*[0-9]*/i
("A1", "E2", "DA19", etc...)
I would like check validity on compilation.
I suppose we can do that with abstract type but I am not sure.
I tried that :
abstract Address(String) to String
{
inline function new(s:String) {
this = s;
}
@:from
static public function fromString(s:String) {
if (!~/[A-Z]*[0-9]*/i.match(s)) {
throw "Invalid adress";
}
return new Address(s);
}
}
But it doesn't work at compilation.
Someone have an idea?
Thanks,
Théo Sabattié.