A method of implementing split names based on jquery (pure JS version) _jquery

Source: Internet
Author: User
Have previously shared a user in the DOM after entering a name automatically with JS split into the first name and the form of jquery plug-ins, due to the needs of the project, a client will be automatically split, but do not need to present the split results to the user's method, so write an independent method, posted to share the exchange with you
Copy Code code as follows:

$.extend ({
Splitname:function (FullName) {
var hyphenated = [' Ouyang ', ' Too history ', ' Duanmu ', ' Officer ', ' Sima ', ' Orient ', ' solitary ', ' nangong ', ' once ', ' wenren ', ' xia-hou ', ' Zhuge ', ' yuchisi ', ' Ram ', ' ' Hector ', ' Dan Tai ', ' Huang Fu ',
' Huizong ', ' Puyang ', ' Gong ye ', ' Uncle Tai ', ' Shen ', ' Gongsun ', ' Murong ', ' Dongsun ', ' clock away ', ' grandson ', ' nonfictional ', ' Fortress ', ' situ ', ' Sainus ', ' sikong ', ' ru Yan ', ' Lu Qiu ', ' che ', ' Shang ',
' Vacant ', ' witch ', ' public West ', ' Zhuan sun ', ' Soil 驷 ', ' Gong Liang ', ' carved lacquer ', ' Le Zheng ', ' kill Father ', ' Guliangzhuan ', ' Tuoba ', ' pinch gu ', ' yuan ', ' Make fox ', ' Duan Gan ', ' bai ', ' Huyan ', ' Dong Guo ', ' South Gate ',
' Goat tongue ', ' micro ', ' Male ', ' Gong Yu ', ' public instrument ', ' according ', ' Gong Zhong ', ' on the public ', ' Public gate ', ' Male mountain ', ' male ', ' left Mound ', ' Male ', ' Simon ', ' Jo ', ' V ', ' male ', ' XI ', ' public ',
' Nam Rong ', ' Dong Li ', ' Orient House ', ' Zhong Chang ', ' Zoshu ', ' sang ', ' Jimo ', ' Da Yu ', ' Chu ';
var vlength = fullname.length;
var lastname = ', FirstName = '; before//Last name, first name
if (Vlength > 2) {
var pretwowords = fullname.substr (0, 2);//Take the first two words named to see if they are in the hyphenated library
if ($.inarray (pretwowords, hyphenated) >-1) {
LastName = 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];
}
});

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.