Posts

Regular expressions for passwords

This is a link post for some of the regular expressions that can be used for passwords.  Specifically, you can use them for asp.net's passwordStrengthRegularExpression. Note: Be sure to test them *before* you use them in a production app. The table indicates the minimum length, if it requires at least one upper, lower, digit or special character. Expression Len Upper Lower Digit Special ^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$ 10 Y Y Y Y ^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$ 8 Y Y Y N ^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$ 10 Y Y Y Y

Links for Linq Joins

Some articles on joins for Linq. This one is basic, just to grok the concept. This post from CodeGuru is a little more detailed and explains things a little better. Multiple join conditions are shown here. This post uses extension methods to handle a date. I can definitely see some uses for this. There are some interesting things you can do like finding all of the overlapping date ranges in a table .

Windows Live Toolbar broke my Shift+Tab

Finally!!!!!! For months my shift+tab in forms didn't work. IE or Firefox. Drove me crazy!!!!! Google a little this morning and found an entry that said uninstall Windows Live Toolbar. Thought "what the heck". It worked!!! Not only did fix IE but it also fixed FF. Don't understand. Don't care. Problem solved. Technorati Tags: Windows Live Toolbar Shift+Tab

Adding commas to numbers with JavaScript

I recently went to add commas to a number on entry. Found a nice script here . Only thing I changed was to make it set the value in the function. I also liked his solution for adding separators other than commas. The code: function addCommas(obj) { nStr = obj.value; nStr += '' ; x = nStr.split( '.' ); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : '' ; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2' ); } obj.value = x1 + x2; }

Parse CSV or other separated strings

I had to work with Comma Separated Values (CSV) files the last few days and updated some code to make it easier to use with LINQ. Quick review, a CSV file is a file that has all of the values separated by a comma. Values that contain a comma are typically qualified with double quotes. For example: Abraham, Lincoln, 03/4/1861, 04/15/1865, "Republican, National Union" Basically, I created a class called SeparatedString that performs all the functionality of parsing the data so that I can retrieve it later. When the Text property is set it figures out the location of all relevant commas and loads them into a List. The GetValue method then uses the index to grab the occurrence of the comma that precedes the value to be retrieved. Public Class SeparatedString ''' <summary> ''' Contains the position of all separator characters in the string ''' </summary> ''' <remarks></remarks> ...

Simple Age Calculation

I was helping someone with some SQL stuff and needed to give them a function to calculate someone's age.  Rooted around a bunch of places and finally just ended up re-writing it. So this is mostly to have it on hand. This function is needed because DateDiff doesn't check if they've had their birthday this year. CREATE FUNCTION CalculateAge ( @ Start smalldatetime , @ End smalldatetime ) RETURNS int AS BEGIN -- Declare the return variable here DECLARE @Age int SET @Age = DateDiff( year , @ Start , @ End ) IF DateAdd( year , @Age, @ Start ) > @ End SET @Age = @Age - 1 RETURN @Age END GO VB Version Public Function Age( ByVal value As Date , ByVal d As Date ) As Integer Age = DateDiff(DateInterval.Year, value, d) If value.AddYears(Age) > d Then Age = Age - 1 Return Age End Function Technorati Tags: SQL Server , Visual Basic , Age , Dates , DateDiff

Use JavaScript on Controls in a GridView, DetailsView or FormView (even in a MasterPage with an UpdatePanel)

Ever want to use JavaScript on a Textbox inside a DetailsView? It can be done, you just need to overcome two issues. The first is that .Net will change the ID from "MyTextBox" to something like "ct100_ContentPlaceholder1_DetailsView1_MyTextBox". The second is that these controls may exist only in Edit or Insert mode. The first thing we want to do is get the ID of MyTextbox that gets sent to the browser. Since MyTextbox only exists when we're editing or inserting, we need to use the PreRender event. We check to make sure we are in Edit/Insert mode and then use FindControl to get a handle on the textbox. Next we use the ScriptManager RegisterHiddenField method to register a hidden control that has the ClientID as its value. Protected Sub DetailsView1_PreRender( ByVal sender As Object , ByVal e As System.EventArgs) Handles DetailsView1.PreRender If DetailsView1.CurrentMode = DetailsViewMode.Edit Or DetailsView1.CurrentMode = DetailsViewMode.Inse...