Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7648749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:47:42+00:00 2026-05-31T10:47:42+00:00

I have written a little JQuery / Javascript add on for our form, that

  • 0

I have written a little JQuery / Javascript add on for our form, that takes a single full name input and breaks it into first and last name components. It opens a modal if there are three or more names in the input and asks which combo is correct.

My next step is finding and stripping any suffix that may have been entered such as Jr, Sr, III, etc. I am currently stripping off the last four characters and checking them with indexOf to see if they contain a suffix string (Jr, Sr, III, etc). But each line checks only one possible suffix and I am wondering is there is some js magic that will check multiple suffixs in one line. My current code is below:

var nameVal = $('#name').val();    
var suffix = nameVal.slice(-4);
if (suffix.toLowerCase().indexOf(" jr") != -1)  { 
    var nameSplit = nameVal.slice(0, -3).split(" "); 
} elseif (suffix.toLowerCase().indexOf(" iii") != -1)  { 
    var nameSplit = nameVal.slice(0, -4).split(" "); 
} else {
    var nameSplit = nameVal.split(" "); }

I can always do the good old || and keep adding extra (suffix.toLowerCase().indexOf(” jr”) != -1) with a different indexOf value, but I am hoping to keep the code more compact if possible, my “little” script is already 3k.

Once I get this sorted the last step will be figuring out how to retain the last name value, so that further down the form when other names are entered and the script is called again it can check to see if the selected last name matches the new entry and bypass the modal pop up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:47:44+00:00Added an answer on May 31, 2026 at 10:47 am

    You can use a regular expression. Try something like this;

    nameVal = nameVal.replace(/ (jr|sr|I?II)$/gi, "");
    

    In more detail;

    (jr|sr|I?II) = jr or sr or II or III
    $ = at the end of line
    /i = case insensitive
    /g match globally
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a simple little form <form id=loginform> <input id=myinput type=text /> <input name=submit
I am learning flex and have written a little app with a TextArea that
I'm using P4COM to communicate with our perforce server. I have written an little
Just wondering what little scripts/programs people here have written that helps one with his
I have a little logging app (written in wxPython) that receives data from a
I have a little routine that's run under Linux and Windows written in C
I have an app that I've written in C#/WinForms ( my little app ).
I have written a little class to persistently memoize some expensive functions that do
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I have written a little program that deletes a record from the database using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.