I know this question will be closed because I studied many example of this but please see I think I am doing something different.  I coded my server side PHP email validation with this:  if (!filter_var($user_new_email, FILTER_VALIDATE_EMAIL)) {         $errors .="Email,";          $pass    = false;              }   My client side email validation is:  function validateEmail(txtEmail){  var a = document.getElementById(txtEmail).value;  var filter = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{1,4}$/;    if(filter.test(a)){     return true;    }    else{     return false;    }   So in my client side if I enter only username@domain (without .com), it's valid. I don't want that.  I need the same validaton in both client and serverside. How to update my regular expression in JavaScript?
291
Is there a regular expression to validate an email address in JavaScript?
38310
Given the following classes and controller action method:  public School {   public Int32 ID { get; set; }   publig String Name { get; set; }   public Address Address { get; set; } }  public class Address {   public string Street1 { get; set; }   public string City { get; set; }   public String ZipCode { get; set; }   public String State { get; set; }   public String Country { get; set; } }  [Authorize(Roles = "SchoolEditor")] [AcceptVerbs(HttpVerbs.Post)] public SchoolResponse Edit(Int32 id, FormCollection form) {   School school = GetSchoolFromRepository(id);    UpdateModel(school, form);    return new SchoolResponse() { School = school }; }   And the following form:  &lt;form method="post"&gt;   School: &lt;%= Html.TextBox("Name") %&gt;&lt;br /&gt;   Street: &lt;%= Html.TextBox("Address.Street") %&gt;&lt;br /&gt;   City:  &lt;%= Html.TextBox("Address.City") %&gt;&lt;br /&gt;   Zip Code: &lt;%= Html.TextBox("Address.ZipCode") %&gt;&lt;br /&gt;   Sate: &lt;select id="Address.State"&gt;&lt;/select&gt;&lt;br /&gt;   Country: &lt;select id="Address.Country"&gt;&lt;/select&gt;&lt;br /&gt; &lt;/form&gt;   I am able to update both the School instance and the Address member of the school.  This is quite nice!  Thank you ASP.NET MVC team!  However, how do I use jQuery to select the drop down list so that I can pre-fill it?  I realize that I could do this server side but there will be other dynamic elements on the page that affect the list.  The following is what I have so far, and it does not work as the selectors don't seem to match the IDs:  $(function() {   $.getJSON("/Location/GetCountryList", null, function(data) {     $("#Address.Country").fillSelect(data);   });   $("#Address.Country").change(function() {     $.getJSON("/Location/GetRegionsForCountry", { country: $(this).val() }, function(data) {       $("#Address.State").fillSelect(data);     });   }); });
262
I don't really understand regular expressions.  Can you explain them to me in an easy-to-follow manner?  If there are any online tools or books, could you also link to them?
14665
I've been looking for a simple regex for URLs, does anybody have one handy that works well?  I didn't find one with the zend framework validation classes and have seen several implementations.
86266
This seems subjective, and it is; a client of mine would like me to highlight the required fields on the web forms in their application with a red asterisk, and I'm looking for an alternative since red asterisks usually mean there's an error to me.  How do I let a user know which fields are required? (One per answer, please.)  UPDATE: This is to indicate which fields are required before validation/postback occurs.
81933
function customization_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {  $form['account']['pass']['#attributes']['placeholder'] = t('Password'); }   I am trying to set placeholder on password field in registration form.  I seted placeholder on username and email, but on password field won't work...  Any help? Thank you!
16097
I wrote a Javascript RegExp test to detect date string format, I added an redundant "g" flag by mistake and found something interesting.  var s = "2009/03/10"; var regex=/^\d{4}[/]\d{2}[/]\d{2}$/g; alert(regex.test(s)); alert(regex.test(s)); alert(regex.test(s)); alert(regex.test(s));   I got a 'true' followed by a 'false', then another 'true', then another 'false'.  If I use a loop to execute it, I found something more interesting, I got four "true" in IE and Safari, and true,false,true,false in FF, Chrome.  for (var i=0; i&lt;4; i++) {   var s = "2009/03/10";   var regex=/^\d{4}[/]\d{2}[/]\d{2}$/g;   alert(regex.test(s)); }   Does anybody has idea to explain why the Javascript regex behaves like that and what cause browsers return different results? ( related to variable declaration and life scope? )
68498
How can I validate some inputs that are not inside a form tag?  All the samples I found have a form tag, but I want to validate some inputs that are not inside a form.
60087
I'm attempting to set up an email template based on the time of day to begin an email with either a "Good Morning" or a "Good Afternoon" greeting based on the time of day that the email was sent.  I see that the {!Now()} function provides me with the current date and time. However, I'm rather new to Salesforce, and haven't been able to figure out how to capture just the time for a comparison in a conditional statement something like Good {!if {!Now()} &lt; "12:00 AM", "Morning", "Afternoon"}.   I've done quite a bit of searching, and haven't yet been able to find an answer to this question. Any help or reference material would be most appreciated. I've already scoured the Salesforce help pages (including the  page), and browsed the internet for a solution.
60853
For context: This is a desktop application interacting with a service running on W7.  I'll try and leave all the technical details out of this, but here goes:  Part of my application has to send a large amount of data to the server which is then validated server side. Any errors found are sent back to the client to handle.  My 'problem' is that this large amount of data (in this case, a person) can have a lot of things 'wrong with it' which can be summarised into two main errors:   Required fields not being filled in. (Name not provided) Data being entered but still invalid due to a business rule (person is under the age of 18, phone number entered as ABC123, assessment was completed, but no completion date was entered, etc.)   Now even with all the client side validation I can put in, there still might be cases when a number of errors that aren't detected. (business rules, mostly) How should these errors be displayed to the client? I only see three real options here:   Displaying the server side errors into the UI somehow. I'd like to avoid this possible since I'm not 100% sure on how to code this without writing a mass of spaghetti code to determine which error is for which field. List one error at a time. When a user submits the data, show the first error that is returned and ignore all the others. When the user resubmits, shows the next one, and so on. I have a feeling this could annoy some people who will probably send me angry emails along the lines of 'Why don't you show me all the errors at once?!?!?' Show them all at once. I could have all the errors showing at once, but this is going to cause a few problems:   The dialog box should potentially be huge if they've somehow got 15 or so errors. No one is going to remember all 15 problems unless they screenshot the message or write them down. The API on Windows might not allow me to fit all message in one dialog leaving users to click through an unknown amount of dialogs.    How should I approach this?
98982
In an AMPscript If statement, is there a way to use "contains" as the operator? For example:  If Var1 Contains "Dog" Then do this  Would I just have to use a regular Expression?  Thanks,  Ben
97576
I have this code that checks that the string contains only space and hash characters (“#”), if so it echos 'yes' if not echos 'no' string=&quot;###############         #             #         # #############         #             #         # ######### # #         #         # # #         # ### ##### # #         #   #     # # #         # # ###########         # #                     ###############&quot;                          confirm_variable=&quot;Yes&quot;  for (( i=0; i&lt;${#string}; i++ )); do     str=&quot;${string:$i:1}&quot;     if [ &quot;$str&quot; == &quot;#&quot; ] || [ &quot;$str&quot; == &quot; &quot; ] || [ &quot;$str&quot; == &quot;\n&quot; ] ;          then             continue         else             confirm_variable=&quot;No&quot;             break     fi  done echo $confirm_variable  I am not sure why this isn't working as if I make the string equal something like: string=&quot;## #### # #  #&quot;   it seems to work fine.
41896
I need to compare 2 strings as equal such as these:     Lubeck == Lübeck   In JavaScript.  Why? Well, I have an auto-completion field that's going out to a Java service using Lucene, where place names are stored naturally (as Lübeck), but also indexed as normalized text,   import sun.text.Normalizer; oDoc.setNameLC = Normalizer.normalize(oLocName, Normalizer.DECOMP, 0)     .toLowerCase().replaceAll("[^\\p{ASCII}]","");   This way some-one who doesn't know to type "Mèxico" can type "mexico" and get a match which returns "Mèxico" (among a lot of other possible hits, like "Café Mèxico, Dubai, UAE").  Now the thing is I don't have the ability to change the service to do any highlighting on the server side, therefore I am highlighting on the client JavaScript side with something like:  return result.replace( input.replace(/[aeiou]/g,"."), "&lt;b&gt;$1&lt;/b&gt;");   It's a little more fancy because I am escaping special regex characters in the input. This is fine for simple one word matches at the beginning of a hit, but it really breaks down if you suddenly wish to support multi-word matches like "london cafe":  input = input.strip().toLowerCase(); //fyi prototype's strip is like trim re = new RegEx(input.replace(/[aeiou]/g,".").replace(/\s+/g,"|"),"gi"); return result.replace(re, "&lt;b&gt;$1&lt;/b&gt;");   This doesn't work for say "london ca" (was typing london cafe), because it would mark "Jack London Cabin, Dawson City, Canada" as: "Ja&lt;b&gt;ck&lt;/b&gt; &lt;b&gt;London&lt;/b&gt; &lt;b&gt;ca&lt;/b&gt;bin, Dawson &lt;b&gt;Ci&lt;/b&gt;ty, &lt;b&gt;Ca&lt;b/&gt;nada" [note the "ck" and "Ci" particularly]  Therefore I'm sort of looking for something that's not as crazy as:  input = input.strip().toLowerCase(); input = input.replace(/a/g,"[ÀàÁáÂâÃãÄäÅåÆæĀāĂăĄą]"); input = input.replace(/e/g,"[ÈèÉéÊêËëĒēĔĕĖėĘęĚě]"); // ditto for i, o, u, y, c, n, maybe also d, g, h, j, k, l, r, s, t, w, z  re = new RegEx(input.replace(/\s+/g,"|"),"gi"); return result.replace(re, "&lt;b&gt;$1&lt;/b&gt;");   Is there a compiled table I can refer to mapping a range of characters which are accented versions of an other character to that character, by which I don't mean the plain unicode chart. And if so, could I avoid using weird, possibly slow, RegEx statements?  About the bounty: Before I started a bounty there were two answers, the one pointing me to doing it in Ruby, and  that  wrote which was a completion of the basic form I'd put in my question. Now don't get me wrong, I really appreciate working it out as completely as he did, but I just wished that there might be another way.  It seems so far that everyone who's dropped by to look at the question and answer has decided that MizzardX covers it just fine, or that they have no different approach. I would be interested in a different approach, and if it simply isn't available before the bounty closes, MizzardX will win the bounty (though in a cruel twist, his edits mad it a community wiki answer, so I'm not sure if he'll get the bounty!)
10505
I have some jQuery/JavaScript code that I want to run only when there is a hash (#) anchor link in a URL. How can you check for this character using JavaScript? I need a simple catch-all test that would detect URLs like these:   example.com/page.html#anchor example.com/page.html#anotheranchor   Basically something along the lines of:  if (thereIsAHashInTheUrl) {             do this; } else {     do this; }   If anyone could point me in the right direction, that would be much appreciated.
30534
I am having a form page called Test Form with this form :  &lt;div id="container"&gt; &lt;form action="wp-content/themes/max-magazine/TestForm.php" method="post" name="myForm"&gt; User &lt;input type="text"  name="uname" /&gt; Email  &lt;input id="email" type="text" name="uemail" /&gt; Password  &lt;input type="password"  name="upass" /&gt; &lt;input type="submit" value="Submit" /&gt;&lt;/form&gt; &lt;/div&gt;   And in backend am having a php file named TestForm.php  &lt;?php  function create_account(){ $user = 'AccountID'; $pass = 'AccountPassword'; $email = 'email@domain.com'; if ( !username_exists( $user )  &amp;&amp; !email_exists( $email ) ) {     $user_id = wp_create_user( $user, $pass, $email );     $user = new WP_User( $user_id );     $user-&gt;set_role( 'contributor' ); }  } add_action('init','create_account'); ?&gt;   Now if this function is defined in function.php then it works fine and create the user but same function in TestForm.php does not work. Please help  Also I will be fetching data from form like this :  &lt;?php $user = $_POST['uname']; $pass = $_POST['upass']; $email = $_POST['uemail']; ?&gt;
90846
I allow users to enter a regular expression to match IP addresses, for doing an IP filtration in a related system. I would like to validate if the entered regular expressions are valid as a lot of userse will mess op, with good intentions though.  I can of course do a Regex.IsMatch() inside a try/catch and see if it blows up that way, but are there any smarter ways of doing it? Speed is not an issue as such, I just prefer to avoid throwing exceptions for no reason.
86088
Ok, there are a million regexes out there for validating an email address, but how about some basic email validation that can be integrated into a TSQL query for Sql Server 2005?  I don't want to use a CLR procedure or function.  Just straight TSQL.  Has anybody tackled this already?