user241423
user241423

Reputation:

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 [email protected])

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

Upvotes: 2

Views: 3070

Answers (3)

LucasElvira
LucasElvira

Reputation: 1

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

Upvotes: 0

FTQuest
FTQuest

Reputation: 546

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

Upvotes: 6

Mantas Vidutis
Mantas Vidutis

Reputation: 16794

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("\.")

Upvotes: 2

Related Questions