In my form I am using drop down for showing day, month, year. can you help me to validate the date. I have to validate the entered age is greater than 15. also checking leap year
I need to validate the contents of a C# method.
I do not care about syntax errors.
I do care about characters that will invalidate parsing of the rest of the code. For example:
method()
{
/* valid comment */
/* <-- bad
for (i..) {
}
for (i..) { <-- bad
}
I need to validate/fix any non-paired characters.
This includeds /* */, { }, and maybe others.
How should I go about this?
I have an app that allows a user to create new projects, and the search for them later. One of the options they have when creating a project is giving them start and end dates. At the moment all the code works properly for creating and searching on the dates, but I am now wanting to restrict what dates the user can enter.
I am needing for an error to flag up when the user tries to enter an end date that is before the start date. It's really more for when the user is creating the project. Here is my code so far =
Application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery.ui.all
//= require_tree .
$(function() {
$("#project_start_date").datepicker({dateFormat: 'dd-mm-yy'});
});
$(function() {
$("#project_end_date").datepicker({dateFormat: 'dd-mm-yy'});
});
jQuery(function(){
jQuery('#start_date_A').datepicker({dateFormat: "dd-mm-yy"});
});
jQuery(function(){
jQuery('#start_date_B').datepicker({dateFormat: "dd-mm-yy"});
});
New View:
<div class="start_date" STYLE="text-align: left;">
<b>Start Date:</b>
<%= f.text_field :start_date, :class => 'datepicker', :style => 'width: 80px;' %>
</div>
<div class="end_date" STYLE="text-align: left;">
<b>End Date:</b>
<%= f.text_field :end_date, :class => 'datepicker', :style => 'width: 80px;' %>
</div>
Search View:
Start dates between
<%= text_field_tag :start_date_A, params[:start_date_A], :style => 'width: 80px;' %>
-
<%= text_field_tag :start_date_B, params[:start_date_B], :style => 'width: 80px;' %></br>
I tried following examples online to get this to work by doing this in the application.js file:
$(function() {
$("#project_start_date,#project_end_date").datepicker({dateFormat: 'dd-mm-yy'});
});
jQuery(function(){
jQuery('#start_date_A,#start_date_B').datepicker({dateFormat: "dd-mm-yy"});
});
But then the script doesn't run. I am new to rails and javascript so any help at all is appreciated. Thanks in advance.
UPDATE:
Don't know why my question has been voted to be closed. It's quite simple:
I need an error to flag up when the user tries to enter an end date that is before the start date. How can I do that??
Hello, I've got a little problem here.
I've got the following rule for one of my fields:
StartDate: {
required: isDelayed,
dateRU: true
}
isDelayed() returns false, so I guess StartDate field should be optional. However if I check it inside my dateRU method:
$.validator.addMethod(
"dateRU",
function(value, element) {
return this.optional(element) || isValidDate($.trim(value));
},
"Date is incorrect"
);
this.optional(element) always returns false for StartDate. I can't figure out what's wrong. Any ideas?
UPD. Does optional() returns true only if element is not required AND IS EMPTY? 'Cause that may be my problem.
i am new to cakephp 2.x so i dont know how to do this .. i want to login the user from his email address and phone number..what my intention is if the number in database is this "12345" and the user is trying to login through this number "+12345" he can be login into the system.. i have written a code but i dont know how can i use this or to adjust my code within the auth component as the auth component is autometically logging the user ..
here is my controller
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->authenticate = array(
'Authenticate.Cookie' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'userModel' => 'User',
'scope' => array('User.active' => 1)
),
'Authenticate.MultiColumn' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'columns' => array('email', 'mobileNo'),
'userModel' => 'User',
)
);
}
public function login() {
if ($this->Auth->login() || $this->Auth->loggedIn()) {
$this->redirect('/users/dashboard');
}else{
$this->layout='logindefault';
$this->set('title_for_layout', 'Account Login');
/*$this->Auth->logout();
$cookie = $this->Cookie->read('Auth.User'); */
if ($this->request->is('post')) {
if ($this->Auth->login() || $this->Auth->loggedIn()) {
if ($this->Session->check('Auth.User')){
$this->_setCookie($this->Auth->user('idUser'));
$this->redirect('/users/dashboard');
} }else {
$this->Session->setFlash('Incorrect Email/Password Combination');
}
}}
}
here is the code which i am trying to add ..
$mobileNo='+123456789';
if (strpos($mobileNo,'+') !== false) {
$mobileNo=str_replace("+", "",$mobileNo);
}
?
What is the meaning of the following error message?How can I use the EnableClienTValidation()?
Error 3 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'EnableClientValidation' and no extension method 'EnableClientValidation' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?) c:\Dev\DEV\test3\Code\MvcUI\Views\Customer\Create.aspx 11 13 MvcUI
I have reference the following:`" type="text/javascript"
<script src="<%=Url.Content("~/Scripts/jquery.validate.js")%>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js")%>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js")%>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/MicrosoftMvcJQueryValidation.js" )%>" type="text/javascript"></script>
`
I am using a javascript function (F) (jquery )which uses 3 select values selected by the user to calculates a value - R(result)
R is a number ranging from (1 through 9), (11) and (22);
I need 2 extra steps one before the calculation and one after.
a. Before calculation takes place:
Make sure all three select values are changed before function(F) takes place. If not prompt the user with a notice ( create dom element/ I am using jquery)
b. After the value R is calculated show an element corresponding to the result e.g. if R is 1 show an element ( a predetermined "link" element corresponding to each result value)
thanks a lot.
I have 'n' number of textbox on a form, after the user enters a value in a textbox, i need to validate its not a duplicate in the other textboxes.
Ex :
Textbox[0] : 1
Textbox[1] : 2
Textbox[2] : 3
Textbox[4] : 1
For this example it should alert saying that '1' have entered twice.
Let me know what to be done.
I have a requirement here to build a comment-like app in my django project, the app has a view to receive a submitted form process it and return the errors to where ever it came from. I finally managed to get it to work, but I have doubt for the way am using it might be wrong since am passing the entire validated form in the session.
below is the code
comment/templatetags/comment.py
@register.inclusion_tag('comment/form.html', takes_context=True)
def comment_form(context, model, object_id, next):
"""
comment_form()
is responsible for rendering the comment form
"""
# clear sessions from variable incase it was found
content_type = ContentType.objects.get_for_model(model)
try:
request = context['request']
if request.session.get('comment_form', False):
form = CommentForm(request.session['comment_form'])
form.fields['content_type'].initial = 15
form.fields['object_id'].initial = 2
form.fields['next'].initial = next
else:
form = CommentForm(initial={
'content_type' : content_type.id,
'object_id' : object_id,
'next' : next
})
except Exception as e:
logging.error(str(e))
form = None
return {
'form' : form
}
comment/view.py
def save_comment(request):
"""
save_comment:
"""
if request.method == 'POST':
# clear sessions from variable incase it was found
if request.session.get('comment_form', False):
del request.session['comment_form']
form = CommentForm(request.POST)
if form.is_valid():
obj = form.save(commit=False)
if request.user.is_authenticated():
obj.created_by = request.user
obj.save()
messages.info(request, _('Your comment has been posted.'))
return redirect(form.data.get('next'))
else:
request.session['comment_form'] = request.POST
return redirect(form.data.get('next'))
else:
raise Http404
the usage is by loading the template tag and firing
{% comment_form article article.id article.get_absolute_url %}
my doubt is if am doing the correct approach or not by passing the validated form to the session. Would that be a problem? security risk? performance issues?
Please advise
Update
In response to Pol question. The reason why I went with this approach is because comment form is handled in a separate app. In my scenario, I render objects such as article and all I do is invoke the templatetag to render the form. What would be an alternative approach for my case?
You also shared with me the django comment app, which am aware of but the client am working with requires a lot of complex work to be done in the comment app thats why am working on a new one.
We have a requirement where we need to allow users to dynamically create custom reports that will run against our database and return sets of data. It would be something similar to this: http://www.marcuswhitworth.com/2009/12/dynamic-linq-with-expression-trees/ but would ultimately contain the ability to create more complicated logic.
I believe LINQ to Entities might possibly allow us to do something like we're attempting to achieve. I should note that these reports are going to need to run against multiple tables. Can anyone point me in the right direction for something like this? Has anyone done anything similar with LINQ to Entities?
After adding the new facebook like button to my page, it no longer validates using XHTML strict. The two errors I come across are:
All of the "meta property" tags say that "there is no attribute "property""
All of the variables used in the like button line are listed that there are no attributes for it. The line is as follows:
<fb:like href="http://www.pampamanta.org" layout="button_count" show_faces="false" width="120" action="like" font="arial" colorscheme="light"></fb:like>
I am looking to add a custom message before listing my errors for a login page:
"Oops, you forgot to enter the following:" + "Username", "Password" (if both not entered)
or
"Oops, you forgot to enter the following:" + "Username" (if just username not entered)
$(document).ready(function(){
$("#loginForm").validate({
errorLabelContainer: $('#RegisterErrors'),
messages: {
username: "Username",
password: "Password"
}
});
});
With this in my HTML
<div id="RegisterErrors">
Hi
I have a form field which requires a json object as its value when it is rendered.
When the form is submitted it returns a comma seperated string of ids as its value (not a json string). however if the form does not validate i want to turn this string of ids back into a json string so it will display properly (is uses jquery to render the json object correctly).
how would i do this?
I was thinking of overwriting the form.clean method but when I tried to change self.data['fieldname'] I got the error 'This QueryDict instance is immutable'
and when i tried to change self.cleaned_data['fieldname'] it didn't make a difference to the value of the field.
Thanks
i dont know whether am only getting this problem or some one else.
When entering string as input in the quantity filed of addtocart input box it never throws error and it takes as 1. how can i validate it. bcz they already made onclick function on addtocart function.
Please help me to solve this
I'm trying to validate a UI change when Enter key is pressed. The UI element is a textbox, which is data binded to a string. My problem is that the data binding hasn't updated TestText when Enter key is Up. It is only updated when I press the button which brings up a message box.
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window, INotifyPropertyChanged
{
String _testText = new StringBuilder("One").ToString();
public string TestText
{
get { return _testText; }
set { if (value != _testText) { _testText = value; OnPropertyChanged("TestText"); } }
}
public Window1()
{
InitializeComponent();
myGrid.DataContext = this;
}
private void OnPropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void onKeyUp(object sender, KeyEventArgs e)
{
if (e.Key != System.Windows.Input.Key.Enter) return;
System.Diagnostics.Trace.WriteLine(TestText);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(TestText);
}
}
Window XAML:
Window x:Class="VerificationTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" KeyUp="onKeyUp"
TextBox XAML:
TextBox Name="myTextBox" Text="{Binding TestText}"
Button XAML:
Button Name="button1" Click="button1_Click"
I am using this technique to place default input in the text fields as a hint to users.
http://www.dailycoding.com/Posts/default_text_fields_using_simple_jquery_trick.aspx
I would like to also validate the fields using jquery validate.
How can i get the validater to ignore the default input?
I not getting the desired effect from a script. I want the password to contain A-Z, a-z, 0-9, and special chars.
A-Z
a-z
0-9 2
special chars 2
string length = 8
So I want to force the user to use at least 2 digits and at least 2 special chars. Ok my script works but forces me to use the digits or chars back to back. I don't want that. e.g. password testABC55$$ is valid - but i don't want that.
Instead I want test$ABC5#8 to be valid. So basically the digits/special char can be the same or diff - but must be split up in the string.
PHP CODE:
$uppercase = preg_match('#[A-Z]#', $password);
$lowercase = preg_match('#[a-z]#', $password);
$number = preg_match('#[0-9]#', $password);
$special = preg_match('#[\W]{2,}#', $password);
$length = strlen($password) >= 8;
if(!$uppercase || !$lowercase || !$number || !$special || !$length) {
$errorpw = 'Bad Password';
I'm trying to validate the entry of text using Python/tkInter
def validate_text():
return False
text = Entry(textframe, validate="focusout", validatecommand=validate_text)
where validate_text is the function - I've tried always returning False and always returning True and there's no difference in the outcome..? Is there a set of arguments in the function that I need to include?
Edit - changed from NONE to focusout...still not working
I have a required attribute that used with resources:
public class ArticleInput : InputBase
{
[Required(ErrorMessageResourceType = typeof(ArticleResources), ErrorMessageResourceName = "Body_Validation_Required")]
public string Body { get; set; }
}
I want to specify the resources be convention, like this:
public class ArticleInput : InputBase
{
[Required2]
public string Body { get; set; }
}
Basically, Required2 implements the values based on this data:
ErrorMessageResourceType = typeof(ClassNameWithoutInput + Resources); // ArticleResources
ErrorMessageResourceName = typeof(PropertyName + "_Validation_Required"); // Body_Validation_Required
Is there any way to achieve something like this? maybe I need to implement a new ValidationAttribute.
For the love of God I am not getting this easy code to work! It is always alerting out "null" which means that the string does not match the expression.
var pattern = "^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$";
function isEmailAddress(str) {
str = "[email protected]";
alert(str.match(pattern));
return str.match(pattern);
}
i have a simple form and when user enters all the information and hits the submit botton than a panel should open just a width of 200px and height of 100px inside the same window. which should have two fields one is captcha image and a text box and a check botton and if captcha code is right than panel should automatically close and redirect to another page just like facebook .
all the details of the panel is saved on another php file.
How to validate a textarea in a form.i.e, it should not be empty or have any new lines and if so raise an alert
<script>
function val()
{
//ifnewline found or blank raise an alert
}
</script>
<form>
<textarea name = "pt_text" rows = "8" cols = "8" class = "input" WRAP ></textarea>
<input type=""button" onclick="val();"
</form>
Thanks