2

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;
        }}
    }

3 Answers3

6

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

FTQuest
  • 546
  • 3
  • 3
  • Exactly the same problem, creating email validation function and it got stuck on the period returning 0. This works perfectly!! – BestAnswer Aug 01 '14 at 05:12
2

search() accepts a pattern, and . just means "a single character", so it is probably returning the first single character, which would most likely be at index 0.

You could try search("\.")

Mantas Vidutis
  • 16,376
  • 20
  • 76
  • 92
0

I try with search(/[.]/) and it worked well in javascript, I think that It would work in the same mode in as3