Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 655 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validating email address using jscript without a regular expression

#1
We can perform a very basic validation of email address with JavaScript by implementing the following three rules:

1.The email address must have @ character

2.The email address must have .(dot) character

3.There must be atleast 2 characters between @ and .(dot)
Reply

#2
Can you try this,


var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

if (!filter.test(email.value)) {
alert('Please provide a valid email address');

Reply

#3
var checkEmail = function(value) {

var valid = true;

if (value.indexOf('@') == -1) {
valid = false;
} else {

var parts = value.split('@');
var domain = parts[1];

if (domain.indexOf('.') == -1) {

valid = false;

} else {

var domainParts = domain.split('.');
var ext = domainParts[1];

if (ext.length > 4 || ext.length < 2) {

valid = false;
}
}

}


return valid;

};

var form = document.getElementById('test');

var validate = function(event) {
event.preventDefault();
var val = document.getElementById('email').value;
var valid = checkEmail(val);

if (!valid) {

alert('Not a valid e-mail address');
} else {

alert('Valid e-mail address');

}
};

form.addEventListener('submit', validate, false);

There are many techniques of validating email address, each validation method has its own pros and cons. The above method doesn't require understanding of regular expressions
Reply

#4
This satisfies all the rules you stated as well as not allowing @ to start the address and not allowing . to end the address. It does not account for multiple . in the address.

function testEmailAddress(emailToTest) {
// check for @
var atSymbol = emailToTest.indexOf("@");
if(atSymbol < 1) return false;

var dot = emailToTest.indexOf(".");
if(dot <= atSymbol + 2) return false;

// check that the dot is not at the end
if (dot === emailToTest.length - 1) return false;

return true;
}

[Fiddle][1]


[1]:

[To see links please register here]

Reply

#5
``This is working...My own Creation :)[Email Validation][1]



[1]:

[To see links please register here]



<input type=”text” name=”email” id=”email” />
<input type=”button” name=”btnok” onclick=”validate()” />


Java Script Function


<script type=”text/javascript”>
function validate()
{
var str;
var t=1;
str =document.getElementById(‘email’).value;
if(document.getElementById(‘email’).value==”")
{
alert(“Empty”);

}
var res = str.split(‘@’);
if(str.split(‘@’).length!=2)
{
alert(“zero @ OR morethan one @ “);
t=0;
}
var part1=res[0];
var part2=res[1];

// part1
if(part1.length==0)
{
alert(“no content bfr @”);
t=0;
}
if(part1.split(” “).length>2)
{
alert(“Invalid:Space before @”)
t=0;
}

//chk afr @ content: part2
var dotsplt=part2.split(‘.’); //alert(“After @ :”+part2);
if(part2.split(“.”).length<2)
{
alert(“dot missing”);
t=0;
}
if(dotsplt[0].length==0 )
{
alert(“no content b/w @ and dot”);
t=0;
}
if(dotsplt[1].length<2 ||dotsplt[1].length>4)
{alert(“err aftr dot”);
t=0;
}

if(t==1)
alert(“woooooooooooooooooooowwwww…it is a valid email”);

}

</script>
Reply

#6
<! -- This pretty much worked for me. Give it a try -->

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

function validateEmail(email) {
var at = email.indexOf("@");
var dot = email.lastIndexOf("\.");
return email.length > 0 &&
at > 0 &&
dot > at + 1 &&
dot < email.length &&
email[at + 1] !== "." &&
email.indexOf(" ") === -1 &&
email.indexOf("..") === -1;
}

function assert(a, b) {
return a == b;
}

console.log(assert(validateEmail("[email protected]"), true));
console.log(assert(validateEmail("[email protected]"), true));
console.log(assert(validateEmail("[email protected]"), true));
console.log(assert(validateEmail("[email protected]"), true));
console.log(assert(validateEmail("[email protected]"), true));
console.log(assert(validateEmail("[email protected]"), true));

console.log(assert(validateEmail("[email protected]"), false));
console.log(assert(validateEmail("[email protected]."), false));
console.log(assert(validateEmail("steve@steve"), false));
console.log(assert(validateEmail("@steve.com"), false));
console.log(assert(validateEmail("steve@"), false));
console.log(assert(validateEmail("steve"), false));
console.log(assert(validateEmail("[email protected]"), false));
console.log(assert(validateEmail("[email protected]"), false));
console.log(assert(validateEmail("[email protected]"), false));

<!-- end snippet -->

<! -- source

[To see links please register here]

-->
Reply

#7
let ValidateEmailAddress = (email) => {
var countAt = 0;
for (let i = 0; i < email.length; i++) {
if (email[i] == '@')
countAt++;
if (!CheckAllowedString(email[i])) {
return false;
}
}
if (countAt > 1 || countAt == 0 ||
IsAllowedCharacter(email.charAt(0)) == false)
return false

var emailParts = email.split('@');
if (emailParts[0].length < 1 || emailParts[1] < 4 ||
emailParts[1].lastIndexOf(".") == -1) {
return false
}

var length = emailParts[1].length;
var lastIndex = emailParts[1].lastIndexOf(".");
if (length - lastIndex <= 2) return false;
//check for -,.,_ double accurance
for (let i = 0; i < email.length; i++) {
if (!IsAllowedCharacter(email[i]) && !IsAllowedCharacter(email[i
+ 1])) return false;
}
for (let i = lastIndex + 1; i < length; i++) {
if (!IsCharacterString(emailParts[1][i])) return false;
}
return true
}
let IsAllowedCharacter = (val) => {
if (typeof val === 'undefined') return true;
if (isCharacterNumeric(val) || IsCharacterString(val)) return true;
return false
}
let isCharacterNumeric = (character) => {
return $.isNumeric(character);
}
let IsCharacterString = (character) => {
var characterArray = ["a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
if (characterArray.indexOf(character.toLowerCase()) != -1) return
true;
return false
}
let CheckAllowedString = (chr) => {
if (chr == '@') {
return true
} else if (chr == '-') {
return true
} else if (chr == '.') {
return true
} else if (chr == '_') {
return true
} else if (IsAllowedCharacter(chr)) {
return true
} else {
return false
}
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through