Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Auto Increment in js with custom prefix

I need to generate a username with prefix start from 00000,so first user should be MS00001 and if reach 100,000 user will be MS100000.

the lastcustomers is query

SELECT * FROM customers WHERE id=(SELECT max(id) FROM customers)

My first idea is to query from my database and get the user id which have auto increment in mysql.

and +1 base on the return id in my input.

<% if(customers=="" ){ %>
      <div class="form-group">
              <label for="addMemberUsername">UserName</label>
               <input value="MS00001" type="text" class="form-control"
                name="addMemberUsername" placeholder="Username">
      </div>
 <% }else { %>
        <div class="form-group">
                <label for="addMemberUsername">UserName</label>
                <input value="MS0000<%= LastCustomers[0].id + 1 %>" type="text"
                 class="form-control" name="addMemberUsername"
                 placeholder="Username">
                 </div>
<% } %>

but this hard code cant change the 10th record to become MS000010, how I make it to MS00010 and if reach 100,000 user will be MS100000.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!