Sponsored Content
Full Discussion: Input Email ID Validation
Top Forums UNIX for Dummies Questions & Answers Input Email ID Validation Post 302898583 by senthil.ak on Tuesday 22nd of April 2014 08:11:07 PM
Old 04-22-2014
Input Email ID Validation

Hi Experts,

I've a script where users will input the email id. I want to loop the script until the user enter proper email id.

Its validating for all condition and error out if any wrong data, but for one condition alone its not erroring out.


Code:
Capture_EmailID()
{
 echo -e "Please Enter email id, Incase you want to enter for muliple email id's please enter all separated by ',' in a single line like below"
 echo -e "abc@app.com,def@app.com"
 echo -e "\033[0;36mEnter the email id/ids \033[0;37m"
 read MAIL_ID
 Validate_Email "$MAIL_ID"
 echo -e "Email Validation Completes, Reports will be send to - \033[0;32m$MAIL_ID\033[0;37m"
}
Validate_Email()
{
echo $1 | awk -F',' '{for(c=1;c<=NF;c++) print $c}' | while read line
do
 nocomma_error_count=$(echo $line | sed 's/com/com\n/g' | grep -c com)
 if [ "$nocomma_error_count" -ge 2 ] ; then
  echo -e "\033[0;31mERROR ::: NOT VALID EMAIL ID - $line having  $error_count email id's not separated by comma (,) \033[0;37m" 
  Capture_EmailID 
 else
   format_error_count=$(echo $line | grep "^[a-zA-Z0-9.]*@app.com$")
   [ "$format_error_count" == "" ] && echo -e "\033[0;31mERROR ::: NOT VALID EMAIL ID $line\033[0;37m" && Capture_EmailID
 fi
done
}

Validation steps

1. It needs to validate if the email id ending with app.com
2. If multiple email id entered, then it need to check for each email id with the format and separated by comma or not

Below is validation missing happening when i enter one correct and one wrong email id. The script is not asking for read command

Code:
$Capture_EmailID
Please Enter email id, Incase you want to enter for muliple email id's please enter all separated by ',' in a single line like below
abc@app.com,def@app.com
Enter the email id/ids
abc@app.com,def@app.comabc@app.com
ERROR ::: NOT VALID EMAIL ID - def@app.comabc@app.com having   email id's not separated by comma (,)
Please Enter email id, Incase you want to enter for muliple email id's please enter all separated by ',' in a single line like below
abc@app.com,def@app.com
Enter the email id/ids
Email Validation Completes, Reports will be send to -
Email Validation Completes, Reports will be send to - abc@app.com,def@app.comabc@app.com
$


Last edited by senthil.ak; 04-22-2014 at 09:12 PM.. Reason: missed to add details
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input validation ?

I am trying to validate user input, at the moment what i have is as below :- echo "\n\tPlease, enter package name to import: \c" read PACKAGE So far this works perfect , But if the user does not input any thing it stalls :( What I need is, If the user does not enter the name of the... (9 Replies)
Discussion started by: systemali
9 Replies

2. Shell Programming and Scripting

EMail Address Validation (Shell Script)

Hi, Can anyone provide me the code snippet for EMail Address Validation. User is going to enter the email address in form window. I need to validate the format is correct. Thanks in Advance BS (3 Replies)
Discussion started by: balajiora
3 Replies

3. Shell Programming and Scripting

Command line user input validation

Hi guys, I have a piece of snippet below which asks the user to input some numbers if isDatasubEnabled && isReconEnabled; then echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit" elif isDatasubEnabled &&... (4 Replies)
Discussion started by: pyscho
4 Replies

4. Shell Programming and Scripting

how to do validation the input requirement with if/else

Hello Everyone, I have the following script; ------------------------------------------------------------------ #!/bin/ksh set HSC=$1 set SEX=$2 set EXP='export ORACLE_SID=AFISDB' if ($#argv !=2); then echo Usage $0 HSC SEX else date > modify_gender_trace.txt $EXP echo... (5 Replies)
Discussion started by: wingcross
5 Replies

5. Shell Programming and Scripting

Input Validation of comma separated values

Hello all, I am working on a script and have the first part solved of numerical input validation. Below the code validates that the input is a numerical value between 100 and 1000. If not, it errors out. Now I need to be able to read values separated by a comma. For example, instead of my... (5 Replies)
Discussion started by: LinuxRacr
5 Replies

6. Shell Programming and Scripting

Input validation of file

Hi, I'm trying to do input validation for a file. If the user fails to enter a file name, the script should prompt for the file name or exit. I'm using this script to integrate with a bigger script which does ftp of the files which are "read". #!/bin/ksh echo "enter a file name" if then... (16 Replies)
Discussion started by: sam_bd
16 Replies

7. Shell Programming and Scripting

perl: How to improve with minimal validation of its input??

The Code: #!/usr/bin/perl use strict; use warnings; print "Please enter numbers, separated by commas: "; my $data=<STDIN>; chomp $data; my @dataset=split(/,/, $data); my $sum = 0; foreach my $num (@dataset) { $sum += $num; } my $total_nums = scalar(@dataset); my $mean =... (1 Reply)
Discussion started by: 300zxmuro
1 Replies

8. Windows & DOS: Issues & Discussions

Validation in user input in batch script

I need to insert the validation in my batch script.When user enter the value it should be numeric+minimum length should be 2 for e.g. 02,03 if he puts 1a,1A,2a3 t hen should print the message that it is wrong and print te message enter valid value. Echo RC is in format of 02 set /p... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

9. Windows & DOS: Issues & Discussions

Put the numeric validation in user input when value is 5.1.2.3

Hi I need to put the validation in batch script when user will enter the build number it should be numeric.I can put the validation for numeric values but there is .(dot) in number so it would not take it as numeric. Is it possible we can store it in variable and remove the .(dot) from the... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

10. Forum Support Area for Unregistered Users & Account Problems

Reset email validation

Guys, I'm coming back from having not visited the site for a several years. I remember my account name (see above), but forgot what I used for my password. Also, My original email address is no longer accessible so I am not able to reset it. I can send someone a private email if to grant... (0 Replies)
Discussion started by: AKelam_MagnusA
0 Replies
Test::Email(3pm)					User Contributed Perl Documentation					  Test::Email(3pm)

NAME
Test::Email - Test Email Contents SYNOPSIS
use Test::Email; # is-a MIME::Entity my $email = Test::Email->new(@lines); # all-in-one test $email->ok({ # optional search parameters from => ($is or qr/$regex/), subject => ($is or qr/$regex/), body => ($is or qr/$regex/), headername => ($is or qr/$regex/), }, "passed tests"); # single-test header methods $email->header_is($header_name, $value, "$header_name matches"); $email->header_ok($header_name, $value, "$header_name matches"); $email->header_like($header_name, qr/regex/, "$header_name matches"); # single-test body methods $email->body_is($header_name, $value, "$header_name matches"); $email->body_ok($header_name, $value, "$header_name matches"); $email->body_like($header_name, qr/regex/, "$header_name matches"); # how many MIME parts does the messages contain? $email->parts_ok($parts_count, "there were $parts_count parts found"); # what is the MIME type of the firs part my @parts = $email->parts(); # see MIME::Entity $parts[0]->mime_type_ok('test/html', 'the first part is type text/html'); DESCRIPTION
Please note that this is ALPHA CODE. As such, the interface is likely to change. Test::Email is a subclass of MIME::Entity, with the above methods. If you want the messages fetched from a POP3 account, use Test::POP3. Tests for equality remove trailing newlines from strings before testing. This is because some mail messages have newlines appended to them during the mailing process, which could cause unnecessary confusion. This module should be 100% self-explanatory. If not, then please look at Test::Simple and Test::More for clarification. METHODS
"my $email = Test::Email->new($lines_aref);" This is identical to "MIME::Entity->new()". See there for details. "$email->ok($test_href, $description);" Using this method, you can test multiple qualities of an email message with one test. This will execute the tests as expected and will produce output just like "Test::Simple::ok" and "Test::More::ok". Keys for $test_href are either "body", or they are considered to be the name of a header, case-insensitive. single-test methods The single-test methods in the synopsis above are very similar to their counterparts in Test::Simple and Test::More. Please consult those modules for documentation. Please note that tests for equality remove newlines from their operands before testing. This is because some email messages have newlines appended to them during mailing. "my $ok = $email-"parts_ok($parts_count, $description);> Check to see how many MIME parts this email contains. Each part is also a Test::Email object. "my $ok = $email-"mime_type_ok($expected_mime_type, $description);> Check the MIME type of an email or an email part. EXPORT
None. SEE ALSO
Test::Builder, Test::Simple, Test::More, Test::POP3 TODO
I am open to suggestions. AUTHOR
James Tolley, <james@cpan.org> COPYRIGHT AND LICENSE
Copyright (C) 2007-2008 by James Tolley This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. perl v5.10.0 2008-10-24 Test::Email(3pm)
All times are GMT -4. The time now is 10:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy