开发者

string.search(".") always return 0

开发者 https://www.devze.com 2023-02-02 04:32 出处:网络
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 {

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.su开发者_运维问答bstr(hDog).search(".");
            trace(hPoint); // PANIC this return always 0
            if(hPoint==-1){
               return false;
        }}
    }


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消