Search code examples
regexapache-flexactionscript-3flashbuilder4

string.search(".") always return 0


I am work in Flash Builder 4. Create e-mail validator on Flex. Have this code

    public var s:String="";

    public function checkSumbols(_s:String=""):Boolean {

        s=_s;  //e-mail address (input mail@supermail.com)

        var hDog:int=0; 
        var hPoint:int=0;
        //check @
        hDog=s.search("@");
        trace(hDog)  // It's work
        if(hDog==-1) {
            return false;
        } else {
            hPoint=s.substr(hDog).search(".");
            trace(hPoint); // PANIC this return always 0
            if(hPoint==-1){
               return false;
        }}
    }

Solution

  • You could use regex. Since dot (.) has special meaning in regex you need to put 'escape' character before: yourString.search(/\./); Should work. HTH FTQuest