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.
Related
This is my search code please see then solution, thank you.
You have to use like this
$report_ex = Expenses::where(condition)->where(condition)->get();
or
$report_ex = Expenses::where(condition)->where(condition)->first();
If you are using
$report_ex = Expenses::where(condition)->where(condition)->first();
then you need to call
if(!empty($report_ex))
{
// your code
}
else
{
//your code
}
But if you are using
$report_ex = Expenses::where(condition)->where(condition)->get();
then you should use
if(count($report_ex) > 0)
{
// your code
}
else
{
// your code
}
since get function returns an empty object
I am using an extension in Magento called web-forms to create all the forms on my website. What I need to do is add the email verification fields (user must enter email twice. Both emails must match) How can I do this? I looked thru the extension but did not see a way to do it.
It looks like the web-forms is using prototype.js for validation.
I got it in case someone in the future has the same problem and in using the web-forms extension here is how you do it.
Assign css class thru the back end in magento->web-forms-(your form name)->the confirm email field(which you should create if you don't have it all ready)design tab->CSS classes for the Input element(put your class name here and remember it you are going to use it later)
Next open up in your root directory of the magento installation the validation.js file. Which is located in js/prototype/
Open the file and paste the code below after the validate-email
['[your class name]', 'Please make sure your emails match.', function(v)
{
var conf = $$('.[your class name]')[0];
var pass = false;
if ($('email')) {
pass = $('email');
}
var emailElements = $$('.validate-email');
for (var i = 0; i < emailElements.size(); i++) {
var emailElement = emailElements[i];
if (emailElement.up('form').id == conf.up('form').id) {
pass = emailElement;
}
}
if ($$('.[your class name]').size()) {
pass = $$('.validate-email')[0];
}
return (pass.value == conf.value);
}],
save it and upload it
Hope that helps somebody you has the same problem.
Above code is not working correctly following part is creating issue
if ($$('.[your class name]').size()) {
pass = $$('.validate-email')[0];
}
at my end following code is working
if ($$('.validate-admin-email').size()) {
pass = $$('.validate-admin-email')[0];
}
so the complete working code can be:
['validate-cemail', 'Please make sure your emails match.', function(v) {
var conf = $$('.validate-cemail')[0];
var pass = false;
if ($('email')) {
pass = $('email');
}
var emailElements = $$('.validate-email');
for (var i = 0; i < emailElements.size(); i++) {
var emailElement = emailElements[i];
if (emailElement.up('form').id == conf.up('form').id) {
pass = emailElement;
}
}
if ($$('.validate-admin-email').size()) {
pass = $$('.validate-admin-email')[0];
}
return (pass.value == conf.value);
}],
.validate-cemail is your defined class in template.
like:
<input type="text" name="email-confirm" id="email-confirm" class="input-text required-entry validate-cemail"/>
public function getWelcome()
{
if (empty($this->_data['welcome'])) {
if (Mage::isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) {
$this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName()));
} else {
$this->_data['welcome'] = $this->__('Welcome, Sign in or Register');
}
}
return $this->_data['welcome'];
}
I want to know if I can use the function Mage::getUrl('/whatever') inside this function.
More specifically, I need to use a link inside the
else {
$this->_data['welcome'] = $this->__('Welcome, Sign in or Register');
}
Thanks.
EDIT
The solution:
$this->__('Welcome, Sign in or Register',
Mage::getUrl('customer/account/login'),
Mage::getUrl('customer/account/create')
);
The __() function works like sprintf(). You can use directives like this:
$this->__('Welcome, Sign in or Register',
Mage::getUrl('customer/account/login'),
Mage::getUrl('customer/account/create')
)
The neat part of this is the directives can be used in any order, you could translate the above to:
Please sign-up or, if you have an existing account,
login. To justify this example here is the register URL again;
<q>%2$s</q>.
I have a multidim array from my $_POST but I have to serialize() then save to the database...
Normally, I can serialize but I got some problem with slashes (apostrophe and double quote).
My array seems like this: $array["hu"]["category"]["food"] = "string";
But when the "string" contains "" or '' theres's shit...
I need some short code for add slashes, but thres a lots of wrong solutions out there.
p.s.: I'm a CodeIgniter user.
// update:
function addslashesextended(&$arr_r) {
if (is_array($arr_r)) {
foreach ($arr_r as &$val){
if( is_array($val) ){
addslashesextended($val);
}else{
$val = addslashes($val);
}
}
unset($val);
} else {
$arr_r = addslashes($arr_r);
}
}
Thx!
I think the best solution would be to use the codeigniter input class and active record class . Addslasches/escapes, and most general sanitization will be taken care of for you.
http://codeigniter.com/user_guide/libraries/input.html
http://codeigniter.com/user_guide/database/active_record.html
How can I create a validator that allows only letters as dashes as input?
Thanks in advance
EDIT
This is what I have so far..
If I write test it passes and if I write 123 it fails but if I write test123 it passes which I don't want
EDIT
The validator now works as I wanted. :)
override protected function doValidation(value:Object):Array
{
results = [];
var regEx:RegExp = /^[a-zA-Z _-]*[a-zA-Z][a-zA-Z _-]*$/;
if(regEx.test(value as String)) {
trace("passed")
return results;
} else {
var err:ValidationResult = new ValidationResult(true,"","","Only letters are allowed");
results.push(err);
trace("error")
}
return results;
}
OK the correct RE is ^[a-zA-Z _-]*[a-zA-Z][a-zA-Z _-]*$