IPv6 Compression
Hi, Please follow the link. It compresses the IPv6 address. In this file it also have to validate the IPv6 address and also It have a function which can Expand the Compressed IP.
Hi, Please follow the link. It compresses the IPv6 address. In this file it also have to validate the IPv6 address and also It have a function which can Expand the Compressed IP.
Here i am sharing a regex to validate the Email.
This is an standard version of regex.
^([a-zA-Z0-9\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+)(?:\.[A-Za-z0-9\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+)*@([a-zA-Z0-9]([\-]?[a-zA-Z0-9]+)*\.)+([a-zA-Z0-9]{0,6})\$
It can validate email like
Valid Emails
arungupta@gmail.com arun+gupta+ramjiki+@gmail.com a.little.lengthy.but.fine@dept.example.com disposable.style.email.with+symbol@example.com other.email-with-dash@example.com arun@daiict.ac.in arun_gupta@gmail.com
Invalid Emails
me@ @example.com me.@example.com .me@example.com me@example..com me.example@com me\@example.com
sub validateDateFormat{
$regexmmddyyyy='^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[- /.]((?:19|20|21)\d\d)$';
$regexddmmyyyy='^(0[1-9]|[12][0-9]|3[01])[-/.](0[1-9]|1[012])[- /.]((?:19|20|21)\d\d)$';
$regexyyyymmdd='^((?:19|20|21)\d\d)[- /.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])$';
$date=shift;
$format = shift;
if($format eq 'ddmmyyyy'){
if(eval $date=~$regexddmmyyyy){
$date = $1;
$month = $2;
$year = $3;
if(isvaliddate($date,$month,$year) eq "true"){
return $year.$month.$date; # Valid date
}else{
return "false"; # Not a valid date
}
}
}elsif($format eq 'mmddyyyy'){
if(eval $date=~$regexmmddyyyy){
$date = $2;
$month = $1;
$year = $3;
if(isvaliddate($date,$month,$year) eq "true"){
return $year.$month.$date; # Valid date
}else{
return "false"; # Not a valid date
}
}
}elsif($format eq 'yyyymmdd'){
if(eval $date=~$regexyyyymmdd){
$date = $3;
$month = $2;
$year = $1;
if(isvaliddate($date,$month,$year) eq "true"){
return $year.$month.$date; # Valid date
}else{
return "false"; # Not a valid date
}
}
}else{
return "false"; # Not a valid date
}
}
## HH:MM:SS is allowed only
sub isvalidtime{
$time = shift;
$regexhhmmss='^(0[1-9]|1[0-9]|2[0-3])[:](0[1-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])[:](0[1-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])$';
if(eval $time=~$regexhhmmss){
return "true";
}else{
return "false";
}
}
sub isvaliddate{
$date = shift;
$month = shift;
$year = shift;
#$date
#$month
#$year
if ($date == 31 and ($month == 4 or $month == 6 or $month == 9 or $month == 11)) {
return "false"; # 31st of a month with 30 days
}elsif ($date >= 30 and $month == 2) {
return "false"; # February 30th or 31st
} elsif ($month == 2 and $date == 29 and not ($year % 4 == 0 and ($year % 100 != 0 or $year % 400 == 0))) {
return "false"; # February 29th outside a leap year
} else {
return "true"; # Valid date
}
}
sub validateDateDifference{
$startdate = shift;
$enddate = shift;
$format =shift;
# Trimming dates and time " 20-01-2013 12.58.1 " --> "20-01-2013 12.59.32"
$startdate =~ s/^\s+|\s+$//g;
$enddate =~ s/^\s+|\s+$//g;
$format=~ s/^\s+|\s+$//g;
($startdate, $startdate_time) = split(/ +/, $startdate);
($enddate, $enddate_time) = split(/ +/, $enddate);
$startdate = validateDateFormat($startdate,$format);
if($startdate eq "false"){
return "false"; # invalid date difference
}
$enddate = validateDateFormat($enddate,$format);
if($enddate eq "false"){
return "false"; # invalid date difference
}
#converting into YYYYMMDD format
if($enddate == $startdate ){
if(isvalidtime($startdate_time) eq "false"){
print "reached";
return "false";
}
if(isvalidtime($enddate_time) eq "false"){
print "reached";
return "false";
}
$startdate_time =~ s/://g;
$enddate_time =~ s/://g;
if($startdate_time < $enddate_time){
return "true"; # Valid date difference
}else{
return "false"; # invalid date difference
}
}
elsif($enddate > $startdate ){
return "true"; # Valid date difference
}else{
return "false"; # invalid date difference
}
}
print 'validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","ddmmyyyy")\t'.validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","ddmmyyyy")."\n";
print 'validateDateDifference("12.12.2014 12:12:58","12.12.2014 12:12:12","ddmmyyyy")\t'.validateDateDifference("12.12.2014 12:12:58","12.12.2014 12:12:12","ddmmyyyy")."\n";
print 'validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","mmddyyyy")\t'.validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","mmddyyyy")."\n";
print 'validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","mmmmyyyy")\t'.validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","mmmmyyyy")."\n";
print 'validateDateDifference("2013-01-31 12:12:58","2013-12-02 12:12:59","yyyymmdd")\t'.validateDateDifference("2013-01-31 12:12:58","2013-12-02 12:12:59","yyyymmdd")."\n";
print 'validateDateDifference("2013-01-31 12:12:58","2013-12-02 12:12:59","yyyymmdd")\t'.validateDateDifference("2013-01-31 12:12:58","2013-12-02 12:12:59","yyyymmdd")."\n";