Search This Blog

Tuesday, November 30, 2010

Common Regular Expressions

Common Regular Expressions




















Field ExpressionFormat SamplesDescription
Name^[a-zA-Z''-'\s]{1,40}$John Doe

O'Dell
Validates a name. Allows up to 40 uppercase and lowercase characters and a few special characters that are common to some names. You can modify this list.
Social Security Number^\d{3}-\d{2}-\d{4}$111-11-1111Validates the format, type, and length of the supplied input field. The input must consist of 3 numeric characters followed by a dash, then 2 numeric characters followed by a dash, and then 4 numeric characters.
Phone Number^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$(425) 555-0123

425-555-0123

425 555 0123


1-425-555-0123
Validates a U.S. phone number. It must consist of 3 numeric characters, optionally enclosed in parentheses, followed by a set of 3 numeric characters and then a set of 4 numeric characters.
E-mail ^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$someone@example.comValidates an e-mail address.
URL^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$http://www.microsoft.comValidates a URL
ZIP Code^(\d{5}-\d{4}|\d{5}|\d{9})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)$12345Validates a U.S. ZIP Code. The code must consist of 5 or 9 numeric characters.
Password(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$ Validates a strong password. It must be between 8 and 10 characters, contain at least one digit and one alphabetic character, and must not contain special characters.
Non- negative integer^\d+$0


986
Validates that the field contains an integer greater than zero.
Currency (non- negative)^\d+(\.\d\d)?$1.00Validates a positive currency amount. If there is a decimal point, it requires 2 numeric characters after the decimal point. For example, 3.00 is valid but 3.1 is not.
Currency (positive or negative)^(-)?\d+(\.\d\d)?$1.20Validates for a positive or negative currency amount. If there is a decimal point, it requires 2 numeric characters after the decimal point.

Thursday, November 25, 2010

How to find all tables and its definition in current sql database

Below query will show you all tables definition with column details.

SELECT
SysObjects.[Name] as TableName,
SysColumns.[Name] as ColumnName,
SysTypes.[Name] As DataType,
SysColumns.[Length] As Length
FROM SysObjects
INNER JOIN SysColumns ON SysObjects.[Id] = SysColumns.[Id]
INNER JOIN SysTypes ON SysTypes.[xtype] = SysColumns.[xtype]
WHERE
SysObjects.[type] = 'U'
ORDER BY SysObjects.[Name]


SysObjects.[Type] value's details

1: C = CHECK constraint
2: D = Default or DEFAULT constraint
3: F = FOREIGN KEY constraint
4: FN = Scalar function
5: IF = Inlined table-function
6: K = PRIMARY KEY or UNIQUE constraint
7: L = Log
8: P = Stored procedure
9: R = Rule
10: RF = Replication filter stored procedure
11: S = System table
12: TF = Table function
13: TR = Trigger
14: U = User table
15: V = View
16: X = Extended stored procedure

Wednesday, November 24, 2010

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during ..

"Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request"

When you are using FormView with ItemTemplate , InsertItemTemplate and EditItemTemplate and you click any event like save, update or delete. After this you click on any postback control then you may get the above exception.

Cause: All template FormView may have different control definition e.g. ItemTemplate does not match control definition with IsertItemTemplate or EditItemTemplate(number of controls or mismatch of control ids')

Solution: Try to keep same control definition in all template

Note: Try to not include ItemTemplate in your FormView

Monday, November 8, 2010

Backup ALL your SQL Server 2005 databases using ONE script

DECLARE @DBName varchar(255)

DECLARE @DATABASES_Fetch int

DECLARE DATABASES_CURSOR CURSOR FOR
select
DATABASE_NAME = db_name(s_mf.database_id)
from
sys.master_files s_mf
where
-- ONLINE
s_mf.state = 0
-- Only look at databases to which we have access
and has_dbaccess(db_name(s_mf.database_id)) = 1

-- Not master, tempdb or model
and db_name(s_mf.database_id) not in ('Master','tempdb','model','ReportServer$SQL2K5','ReportServer$SQL2K5TempDB')
group by s_mf.database_id
order by 1

OPEN DATABASES_CURSOR
FETCH NEXT FROM DATABASES_CURSOR INTO @DBName
WHILE @@FETCH_STATUS = 0
BEGIN
declare @DBFileName varchar(256)
set @DBFileName = datename(dw, getdate()) + ' - ' +
replace(replace(@DBName,':','_'),'\','_')
exec ('BACKUP DATABASE [' + @DBName + '] TO DISK = N''E:\DatabaseBACKUP\' +
@DBFileName + ''' WITH NOFORMAT, INIT, NAME = N''' +
@DBName + '-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD, STATS = 100')

FETCH NEXT FROM DATABASES_CURSOR INTO @DBName
END
CLOSE DATABASES_CURSOR
DEALLOCATE DATABASES_CURSOR