Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends

I have small doubt that can we pass more than one delimiter to javascrit split function to check with the string.
See below code

XML
var leapyear = new Array();
leapyear =date.split("/");  <-Here I want to pass more than one delimiter 
alert(leapyear[2]);
for (var i = 0; i < leapyear.length; i++)
  document.writeln("<h4>" + leapyear[i] +"</h4>");
  return true;



So that I can check in which format the user entered the date like DD/MM/YYYY or DD-MM-YYYY or DD.MM.YYYY with these three delimiters " /,-,.".


Thanks in Advance
Ganesh
Posted

 
Share this answer
 
Comments
Manas Bhardwaj 21-Aug-12 3:58am    
Good directions +5!
Prasad_Kulkarni 21-Aug-12 4:40am    
:) Thank You Manas!
try below code...
you just take 3rd no string and split using taht string... you don't need to pass multiple parameters...
if your date is "12/01/2012" or "12-01-2012" or "12.01.2012"
below code will return correct answer..

JavaScript
var leapyear = new Array();
leapyear =date.split(date.substr(2,1));  
alert(leapyear[2]);
for (var i = 0; i < leapyear.length; i++)
  document.writeln("<h4>" + leapyear[i] +"</h4>");
  return true;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900