Method of splitting names based on jquery [pure JavaScript version]

Source: Internet
Author: User

You have previously shared a jquery plugin in the DOM that is automatically separated by a user's name and name into the form in a table. Because of the needs of the project, a method that automatically splits at the client, but does not need to present the split results to the user, is written in a separate way, Post it and share the conversation with you.

$.extend ({splitname:function (fullname) {var hyphenated = [' Ouyang ', ' Too history ', ' Duanmu ', ' Officer ', ' Sima ', ' Oriental ', ' solitary ', ' nangong ', ' As soon as ', ' wenren ', ' xia-hou ', ' Zhuge ', ' yuchisi ', ' Ram ', ' Hector ', ' Dan Tai ', ' Huang Fu ', ' huizong ', ' Puyang ', ' Gong ye ', ' Tai tert ', ' Shen ', ' Gongsun ', ' Murong ', ' Dongsun ', ' clock away ', ' grandson ', ' nonfictional ', ' Castle ', ' Stu ', ' Sainus ', ' sikong ', ' ru Yan ', ' Lu Qiu ', ' che ', ' Shang ', ' vacant ', ' witch ', ' Percy ', ' Zhuan sun ', ' Soil 驷 ', ' Gong Liang ', ' carved lacquer ', ' Le Zheng ', ' kill Father ', ' Guliangzhuan ', ' Tuoba ', ' pinch gu ', ' yuan ', ' Make fox ', ' Duan Gan ', ' Barry ', ' Huyan ', ' Dong Guo ', ' South Gate ', ' goat tongue ', ' micro ', ' Male ', ' Gong Yu ', ' public instrument ', ' according ', ' Gong Zhong ', ' on the public ', ' Public gate ', ' Male mountain ', ' public ', ' left Mound ', ' Male ', ' Simon ', ' Male ', ' V ', ' gong ', ' Guan    
        Qiu ', ' Gong Xi ', ' Nam Rong ', ' Dong Li ', ' Orient House ', ' Zhong Long ', ' Zoshu ', ' sang ', ' Jimo ', ' Da Yu ', ' Chu ';    
        var vlength = fullname.length; var lastname = ', FirstName = ';//Last name, after name if (Vlength > 2) {var pretwowords = Fullname.sub STR (0, 2);//Take the first two words that are named and see if they are in the hyphenated library if ($.inarray (pretwowords, hyphenated) >-1) {Lastna    
                me = pretwowords;    
            FirstName = FULLNAME.SUBSTR (2); }else{LastName = fullname.substr (0, 1);    
            FirstName = FULLNAME.SUBSTR (1);    
            }}else if (vlength = = 2) {//Full name only two words, before one for last name, later for name LastName = FULLNAME.SUBSTR (0, 1);    
        FirstName = FULLNAME.SUBSTR (1);    
        }else{LastName = fullname;    
    return [LastName, FirstName]; }    
});

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/jquery/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.