473,396 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

validate the company registration number in JavaScript

I want to validate company registration number in JavaScript which should be 14 characters long.

EG : 1993/041545/23

Currently this how I validate it.

HTML CODE

Expand|Select|Wrap|Line Numbers
  1.  
  2. <label >Registration Number:</label></br>
  3. <div class="warn"><span id="statusRegisternumber"></span></div>
  4.  <input type="hidden" id="registernumber" class="hiddenId value=" Value="" />
  5. <input type="text" name="registernumber" id="registernumber" onkeyup="validate_registernumber(this.value);"   placeholder="Registration Number" title="Please provide a valid company registration number" <?php getpostvalue('registernumber');?>/></br>
  6.           </p>
  7.  

JAVASCRIPT CODE

Expand|Select|Wrap|Line Numbers
  1. function validate_registernumber(registernumber)
  2. {
  3.   var regRegisternumber =  /^[0-9]{14}$/;        
  4.   if(regRegisternumber.test(registernumber) == false){
  5.          document.getElementById("statusRegisternumber").innerHTML = "Registration Number is not valid";
  6.   }else{                        document.getElementById("statusRegisternumber").innerHTML = "You have entered a valid Registration number";
  7.     }
  8.  
Nov 10 '15 #1

✓ answered by Dormilich

you can shorten that considerably: /^[\d/]{14}$/

11 2695
Dormilich
8,658 Expert Mod 8TB
your RegExp looks for 14 digits, not for 4 digits followed by a slash followed by 6 digits followed by a slash followed by 2 digits.
Nov 10 '15 #2
Okay, please give me the best regex, i tried to do it in this order "4 digits followed by a slash followed by 6 digits followed by a slash followed by 2 digits. " but didn't work maybe, there is something m doing wrong
Nov 10 '15 #3
Dormilich
8,658 Expert Mod 8TB
i tried to do it in this order "4 digits followed by a slash followed by 6 digits followed by a slash followed by 2 digits. " but didn't work maybe, there is something m doing wrong
if you post your trial, I can tell you what was wrong. (I would stab a guess at unescaped characters)
Nov 10 '15 #4
He is my regex:

Expand|Select|Wrap|Line Numbers
  1. /^[0-9/]{4}[0-9/]{6}[0-9/]{2}$/
Nov 10 '15 #5
Dormilich
8,658 Expert Mod 8TB
[0-9/]{4} that looks for 4 characters, which can be either a digit or a slash. i.e. //// would match as would 8/15. in the end your Regexp is 2 characters short the requirement.
Nov 10 '15 #6
I can put in 1224/145874/
But i cant put in 224/145874/21
Nov 10 '15 #7
Dormilich
8,658 Expert Mod 8TB
that’s correct.
in the end your Regexp is 2 characters short the requirement.
Nov 10 '15 #8
This sort out my error
Expand|Select|Wrap|Line Numbers
  1. /^[0-9/]{4}[0-9/]{8}[0-9/]{2}$/
. Thanks buddy.
Nov 10 '15 #9
Dormilich
8,658 Expert Mod 8TB
you can shorten that considerably: /^[\d/]{14}$/
Nov 10 '15 #10
That will be awesome, nice and short
Nov 10 '15 #11
Dormilich
8,658 Expert Mod 8TB
and it will allow some values that are clearly not a registration number.
Nov 10 '15 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: varois83 | last post by:
Hi Newbie here. I have been working on creating a guestbook for my site as practice and am learning a lot. Do you guys validate your forms first on the client with javascript and then on the...
2
by: Ori | last post by:
Hi, I'm looking for a good way to validate a US phone number and i though using regular expression for this. I want to support 3 different ways to enter a phone number: 1.Local Phone : 888-8899...
3
by: DAVE Reed | last post by:
How or where do I get the registration number required to register my copy of Visual Basic 2005 (VB.NET)?
3
by: OBA | last post by:
Hi To All.... This Is My First Try To Create A Program Which Compose A Server And 2 Client...i Use Access Database As My Back End And Vb6 As My Front End... Problem 1. I Create A Code In...
5
by: Abhishek | last post by:
Hi this is my another validator in javascript to validate the Phone Number :-) <script language='javascript'> function funcCheckPhoneNumber(ctrtxtMobile,e){ if(window.event){ var strkeyIE =...
5
by: ghjk | last post by:
I have a web site with several web pages. They are having different number of variables. eg: first page having 4 variables in the form(Name, Phone, ID, Gender) second page having 10 variables in the...
4
by: govind161986 | last post by:
How do I validate a file size using javascript? Thanks in advance, Govind
2
by: Bala Kumaran | last post by:
Hi Experts, I've created a resulting script like this search.php <?php // Make a MySQL Connection mysql_connect("localhost", "db_user_name", "db_user_password) or...
3
by: komathi043 | last post by:
i need to validate a form using javascript.But it should not validate with mssbox.i need different method for displaying err msg
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.