Hello,
I’m having a problem with using regexp to validate form fields, everything is working fine as long as I don’t explicitly try to match a dot(.) character. This fails on both email and the voorletters regex.
I’ve tested both these regexes in RegExr and they are doing what they’re supposed to there.
Can anyone point me towards whats the problem?
var regex_voorletters:RegExp = /^([A-Z\.])+$/i;
var regex_email:RegExp= /^([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})$/i
private function regex_test_textfield(tfield:TextInput, regex:RegExp):Boolean {
trace ("Test called"+tfield.id)
var test:Boolean= (tfield.text.search(regex)==0);
if (!test) {
tfield.setStyle("backgroundColor","0xFF9999"); // red
trace("Regex failed. Input: "+tfield.text);
return false;
} else {
trace("Regex ok. Input: "+tfield.text);
tfield.setStyle("backgroundColor","0x99FF99"); //green
return true;
};
}