Home


.Net, SQL and softball. Musings of a software developer with a softball problem

Tuesday, August 26, 2008

Got Skills?

No that really isn't a question posed to you my reader. Nor is it a rhetorical question. That is the name of the softball team we were supposed to play this weekend.

It was our season opener this Sunday, but our opponents didn't show. I think they had their weekends mixed up. So they had to forfeit since they weren't there. First 2 wins of the season. And since this is the Fall season we only play each team once, so we won't be playing these guys at all, which is a shame.

But since we had the field for the next hour and forty minutes we scrimmaged an all guys team that was playing a field over. They were a lot of fun. Their first baseman played with his glove on one hand and a beer in the other. I wish I could get away with that...

Anyway good little game with a lot of our new players. I think this is going to be a good season. No game next week cause of Labor Day.

Labels:

posted by Tom Becker at | 0 Comments

Wednesday, August 20, 2008

Extending the .Net Validators

Been a while since I've had a .Net post. Haven't been doing to much development right now. Mostly maintenance work so haven't really be doing anything worthy of a post.

But my co-workers and I have been working on a set of tools that we all use that we should standardize. No sense in all of us writing the same code. One of the biggest differences is how we all handle our input validation. I have been using all the built in RequiredFieldValidators (msdn), CompareValidators (msdn), and the occasional RegularExpressionValidator (mdsn) and others have been spinning their own solutions. So we all go together and hashed out what we all wanted out of our validation, and I ended up writing a custom validator that blended the options.

At first I was going to just try to extend the CompareValidator to add the data types that I/we wanted but that really isn't an option since you can't tap into the ValidationDataType that the control uses. So I ended up starting from scratch essentially and just extended the BaseValidator (msdn) and just wrote my own validate function. See below for code.


Option Strict On
Option Explicit On

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace CustomControls

Public Class myValidator
Inherits BaseValidator

Public Enum FormatTypes
PhoneNumber
SSN
Email
DateTime
StrictAlpha
Alpha
Numeric
AlphaNumeric
ZipCode
URL
End Enum


Private _type As FormatTypes

'''
''' What kind of format do you want the data in
'''

Public Property DataType() As FormatTypes
Get
Return _type
End Get
Set(ByVal value As FormatTypes)
_type = value
End Set
End Property

Dim _isRequired As Boolean = False
Public Property Required() As Boolean
Get
Return _isRequired
End Get
Set(ByVal value As Boolean)
_isRequired = value
End Set
End Property


Protected Overrides Function EvaluateIsValid() As Boolean
Dim expression As String = ""
Dim stringToValidate As String = Me.GetControlValidationValue(Me.ControlToValidate)
Dim isValid As Boolean = False


If _isRequired And Trim(stringToValidate) = "" Then
isValid = False
ElseIf Not _isRequired And Trim(stringToValidate) = "" Then
isValid = True
Else
Select Case _type
Case FormatTypes.Email : expression = "^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}"
Case FormatTypes.PhoneNumber : expression = "((\(\d{3}\) ?)|(\d{3}[- \.]))?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$"
Case FormatTypes.SSN : expression = "\d{3}-\d{2}-\d{4}"
Case FormatTypes.Alpha : expression = "^[a-zA-Z ,-.:/_?!']*$"
Case FormatTypes.AlphaNumeric : expression = "^[a-zA-Z0-9 ,-.:/_()?!]+$"
Case FormatTypes.DateTime : expression = "^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|
[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))
|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|
$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$"
Case FormatTypes.Numeric : expression = "^[0-9]*$"
Case FormatTypes.StrictAlpha : expression = "^[a-zA-Z]*$"
Case FormatTypes.URL : expression = "^(http\:\/\/[a-zA-Z0-9_\-]+(?:\.[a-zA-Z0-9_\-]+)*\.[a-zA-Z]{2,4}(?:\/[a-zA-Z0-9_]+)
*(?:\/[a-zA-Z0-9_]+\.[a-zA-Z]{2,4}(?:\?[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)?)?(?:\&[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)*)$"
Case FormatTypes.ZipCode : expression = "(\d{5}-\d{4})|(\d{5})$"

End Select

If Regex.IsMatch(stringToValidate, expression) Then
isValid = True
Else
isValid = False
End If
End If

Return isValid
End Function
End Class

End Namespace


So that is the class. There are some pretty hefty regular expressions in there. But don't let them scare you. You set them and forget them. I had to break the lines a bit to get them to look nice on the screen.



So to get it on the page you are going to need to register the namespace. Example below:
<%@ Register TagPrefix="vld" Namespace="CustomControls">

Once you've got it registered (you can put it in the web.config file as well if you don't want to declare it on every page) you can actually use the control. You can use it just like you would with the RequiredFieldValidator. See example below:
<vld:myValidator ID="cusEmail" DataType="Email" required="false" ControlToValidate="txtEmail" ErrorMessage="Enter valid email address" Display="dynamic" runat="Server">*</vld:myValidator>
And thats pretty much it. The DataType property will list all of the values you have defined in the code file. To add more data types you can add it to the formatType enum and just add the regEx to the case statement in the validate function and you are good to go.

Labels:

posted by Tom Becker at | 1 Comments

Tuesday, August 5, 2008

End of Season Stats

On of my teammates took home the score book this week to do some statistics. And I thought I'd post them here for any major league recruiters.

Batting Average:.688
On-Base Percentage:.778
Slugging Percentage: .969
On-Base + Slugging: 1.747

Not to shabby. Now our best player's stats (and the one who did them) are...
Batting Average:.576
On-Base Percentage:.682
Slugging Percentage:1.303
On-Base + Slugging:1.985

So it would seem that I should be batting before him since I am more likely to get on base, but he is more likely to drive in runs than I am.

And just for the record, I didn't come up with any of this, this is all from Richie and the Fiancee, I am just putting them out here.

Labels:

posted by Tom Becker at | 0 Comments

Monday, August 4, 2008

The Tornadoes

This was the last series of the season for me as I will be on vacation next week, so I will miss our season closer. A little sad, but I need the vacation so it will all be good.

We played the Tornadoes yesterday, and I had a very good time, not only did I play pretty well, but they are a very fun team to play. We lost both games, but I think everyone had a good time over all. We even had our biggest fans stay and watch our games after they finished. Hi Miss Piggy and Beaker!

We didn't have our full normal team, but some people who are going to play fall ball with us came out ready to play and they filled in for us. One girl in particular has a hell of a bat, she is going to be a great addition for fall ball. Even with her though we got trounced this game. I really think the Tornadoes strength is their consistency. They have a few power hitters that can knock it out of the park, but they usually don't. They all just try for a base hit, or at most a double, of course they will go for more when they can, but almost all of their team get on base every at bat. So that just pushes people around the bases and they always end up racking up big numbers. The first game I think they beat us 10-3 or something like that.

The next game was kinda a heart breaker. We are at bat first and score 13 runs the first inning. They come up and score 3 by the end of the inning. So we are feeling pretty good at this point, thinking we have it clinched, but they come back and score 13 the next inning after keeping us scoreless, so that puts them up 16-13. Last inning of the game we just have to score 3 in order to keep us alive, but we just couldn't pull it off.

I had a lot of fun at my last game and I think I played very well. I will be taking over managing the Sunday Scared Hitless team while the other captain will take the Tuesday night league for fall ball. And that season starts in a few weeks. Once I figure out how we do next week, I'll post our final league standings.

Labels:

posted by Tom Becker at | 0 Comments