I'm trying to get this bit of code in my cfscript tag to work. I've searched and searched but have some up with nothing which will work to validate the email address.
If the email address is blank it will return the errormessage but if I just type on character, it will let it pass.
I'm pretty new to scripting in CF so any help would be appreciated.
if (isDefined("form.email"))
{
if (form.email is "")
{
errormessageemail = "Please enter a valid Email Address!";
}
else if (not form.email is "")
{
email = form.email;
function validate_email(str,email) {
if( not len(trim(arguments.str)) or not refind("^[0-9A-Za-z.'+_-]+#([0-9A-Za-z-]+\.)+[A-Za-z]+$", trim(arguments.str)) ) {
errormessageemail = "Please enter a valid Email Address! Ex. abc#abc.com";
}
return errormessageemail;
}
}
}
It could be as simple as this:
if (StructKeyExists(form, "email") AND NOT isValid("email", form.email)) {
errormessageemail = "Please enter a valid Email Address!";
}
You don't validate if email is not posted. Blank string is not valid email, no need to check it specially.
Note: someone may argue that isValid/email does not work 100% properly. That's true, but rare problem. Use regex if you think so as well.
Here's the code I use for checking for email validity:
LOCAL.Email = trim(lCase(ARGUMENTS.Email));
LOCAL.IsValid = reFindNoCase("^[A-Z0-9._%+-]+#[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$", LOCAL.Email);
And you should test for your form with structKeyExists, not isDefined, like the other respondent suggested. The structKeyExists function searches a specific scope for the variable. isDefined searches any and every scope.
if (StructKeyExists(form, "email") AND NOT isValid("email", form.email)) {
errormessageemail = "Please enter a valid Email Address!";
}
Simply Email validity Check in CFM
<cfif isValid("email", #Form.email#) >
<cfoutput>Email Address is valid</cfoutput>
<cfelse>
<cfoutput>Email Address is invalid</cfoutput>
</cfelse>
Related
Im trying to send two variables with get to a php file that contains an xlm format
function process(){
if (xmlHttp){
try{
email = encodeURIComponent(document.getElementById("email").value);
if (email=="") {email="empty email"};
xmlHttp.open("GET", "user_check.php?email=" + email, true);
username = encodeURIComponent(document.getElementById("username").value);
if (username=="") {username="empty username"};
xmlHttp.open("GET", "user_check.php?username=" + username, true);
the php file looks like
echo '<response>';
echo '<username>';
$username = ( isset($_GET['username']) ? $_GET['username'] : "something empty");
echo $username;
echo '</username>';
echo '<email>';
$email = ( isset($_GET['email']) ? $_GET['email'] : "something empty");
echo $email;
echo '</email>';
echo '</response>';
when i echo those variables it shows only one, actually it sends only the username which is the second on list(from top to bottom) that is sent. How can i send both or later more variables
function handleResponse(){
message_email = xmlHttp.responseXML.documentElement.getElementsByTagName("email").item(0).firstChild.data;
next_email = document.getElementById("next_email");
next_email.innerHTML =message_email;
message_username = xmlHttp.responseXML.documentElement.getElementsByTagName("username").item(0).firstChild.data;
next_username = document.getElementById("next_username");
next_username.innerHTML =message_username;
}
the output of this is
email : something empty
username : "the value from input"
i want email to have its value from its input.
I hope i made my question clear.
As far as I can understand you, you have to put both of variables into one request, because now, you are sending two requests, after everything reading only second one.
To send two variables in one GET request you use something like:
http://example.com/response.php?var1=foo&var2=bar
resulting in PHP:
$_GET['var1'] = "foo";
$_GET['var2'] = "bar";
So your AJAX code should look like:
email = encodeURIComponent(document.getElementById("email").value);
if (email=="") {
email="empty email"
};
username = encodeURIComponent(document.getElementById("username").value);
if (username=="") {
username="empty username"
};
xmlHttp.open("GET", "user_check.php?email=" + email + "&username=" + username, true);
Important thing is that order of GET variables doesn't matter - you can put email or username first, they will both be loaded into $_GET[] array.
I have made code with is work great for me, but I want to make email validation to require # on the field. Here is the code
if (!$('#contact_email').val()) {
if ($("#contact_email").parent().next(".validation").length == 0) // only add if not added
{
$("#contact_email").parent().after("<div class='validation' style='color:red;margin-bottom: 20px;'>Ange e-postadress</div>");
}
e.preventDefault(); // prevent form from POST to server
$('#contact_email').focus();
focusSet = true;
} else {
$("#contact_email").parent().next(".validation").remove(); // remove it
}
And the input is
<input type="text" class="form-control" placeholder="E-post" name="Email" id="contact_email" onblur="validate()">
I dont use basic email field because I don't want to be on english.
How can i implement # to be required on this text input. Thank you
Hey Use This function:
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s#"]+(\.[^<>()[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
found here:
Validate email address in JavaScript?
Try this for email validation:
function isEmail(email) {
var mailformat = /^\w+([\.-]?\w+)*#\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (email.match(mailformat)) {
return true;
} else {
return false;
}
}
Checking as follows:
if (email != "") {
if (!isEmail(email)) {
alert("invalid");
}
}
You can use regular expression to check for an "#" and a "." field.
Regex:
var regex= /\S+#\S+\.\S+/;
return regex.test(email);
The above code will return true if the regular expression is matched. This expression checks for an # and a . to be present in the given string.
Heres the documentation on .test http://www.w3schools.com/jsref/jsref_regexp_test.asp
I've noticed other answers have better regular expressions as the above will allow for multiple #'s and .'s to be present.
RadInputPrompt.Show("Enter the number", MessageBoxButtons.OK, message, InputMode.Text, textBoxStyle, closedHandler: (arg) =>
{
int okButton = arg.ButtonIndex;
if (okButton == 0)
{
//do some check before submit
if (string.IsNullOrEmpty(arg.Text))
{
MessageBox.Show("Please input the number.");
return; //??
}
//submit
}
else
{
return;
}
});
My question is :
I do some data validation (for example: numeric only, the digit count...) before submit
If the input from user is invaild, I hope the Prompt Input Screen can still remain.
If I use "return" keyword, it'll go back to the main screen.
Or is there any other ways of validation (something like AJAX?) that I can use on this prompt sceen rather than do it on code-behind page?
Thanks a lot!
One technique is to just keep looping and showing the input prompt each time the user clicks OK, but fails to satisfy the input validation. You can see an example of this below with the input text box continuing to repeat if the result is not a valid numeric value.
It's also a good idea to add some kind of feedback to the user indicating that the previous input was not acceptable in the event of an invalid submission. An example of this is below where the title of the input text box is changed after the first invalid submission to include text indicating that the input value must be a valid number.
NOTE: Telerik is saying the ShowAsync method should now be used instead of the Show method since it is being deprecated.
string userInput = string.Empty;
int okButton = 0;
bool firstPass = true;
double numericResult;
while (okButton.Equals(0) && string.IsNullOrWhiteSpace(userInput))
{
string inputBoxTitle = (!firstPass) ? "Enter the number (you must enter a valid number)" : "Enter the number";
InputPromptClosedEventArgs args = await RadInputPrompt.ShowAsync(inputBoxTitle, MessageBoxButtons.OKCancel);
okButton = args.ButtonIndex;
firstPass = false;
if (okButton.Equals(0))
{
if (!string.IsNullOrWhiteSpace(args.Text))
{
bool isNumeric = double.TryParse(args.Text, out numericResult);
if (isNumeric)
{
// We have good data, so assign it so we can get out of this loop
userInput = args.Text;
}
}
}
}
I'm using a model with DataType.EmailAddress. I would like to modify the address link in the run time, however it already has email link automatically that prevents my modification.
#{
var subject = "";
if (Model.Name.Length > 30)
{
subject = Model.Name.Substring(0, 30) + "...";
}
else
{
subject = Model.Name;
}
}
model => model.email
But I got
<a href="mailto:emailaddress">emailaddress</a>
instead of
emailaddress
Why the email address is converted into link form automatically? And how to stop it? I would like to keep the datatype to use validation though.
You're trying to print the value of the property: #model.Email.
DisplayFor is not what you want.
Also, you need to URL-encode the subject parameter, including the space after Re:.
I searched a lot to remove required fields like first name, Last name and confirm passwordfields in account create page.
So far i renamed required value from 1 to 0 from the table eav_attribute
After this i hided first name, Last Name, Confirm Password from register.phtml
But still i'm getting
The first name cannot be empty, The Last name cannot be empty, etc,..
Did any one know how to do this ?
Please give me a idea to solve this..
You have to change two more files:
Change /js/prototype/validation.js and comment out the following lines:
['validate-cpassword', 'Please make sure your passwords match.', function(v) {
var conf = $('confirmation') ? $('confirmation') : $$('.validate-cpassword')[0];
var pass = false;
if ($('password')) {
pass = $('password');
}
var passwordElements = $$('.validate-password');
for (var i = 0; i < passwordElements.size(); i++) {
var passwordElement = passwordElements[i];
if (passwordElement.up('form').id == conf.up('form').id) {
pass = passwordElement;
}
}
if ($$('.validate-admin-password').size()) {
pass = $$('.validate-admin-password')[0];
}
return (pass.value == conf.value);
}],
After that, you also have to change the Magento Customer Core model. There are two types of validation: through the front-end javascript and in the backend Customer model.
Rewrite the model with your own customer module. Then copy the validate() public function. And comment out the following lines:
$confirmation = $this->getConfirmation();
if ($password != $confirmation) {
$errors[] = Mage::helper('customer')->__('Please make sure your passwords match.');
}