UK Postcode Validation

Regular expression for JavaScript var regPostcode = /^([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([ ])([0-9][a-zA-z][a-zA-z]){1}$/; var result = regPostcode.test(SearchTerm); if (!result) { alert(“Please enter valid postcode”); return false; } Regular expression for C# string regPostcode = “([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([ ])([0-9][a-zA-z][a-zA-z]){1}”; System.Text.RegularExpressions.Regex regx = new…

Read More

SQL Server Transaction

BEGIN TRANSACTION BEGIN TRY — put SQL commands here INSERT/UPDATE/Delete — if successful – COMMIT the work COMMIT TRANSACTION END TRY BEGIN CATCH — handle the error case (here by displaying the error) SELECT ERROR_NUMBER() AS…

Read More

How to display Progress bar while page is loading

<pre> <code> protected void Page_Load(object sender, EventArgs e) { showPageLoad(); //do somthing     } private void showPageLoad() { int i=0; Response.Write(“<div id=’divTitle’>Loading(<span id=’message’>0%</span>)</div>”); Response.Flush(); for(i=5;i<=100;i=i+5) { System.Threading.Thread.Sleep(200);// any codes can be typed here outputflash(i.ToString() + “%”);…

Read More

Download / Upload Files on FTP Server

Require following ftp details where you want to upload the files: FTP URL: “ftp://ftp.yoursite.com/” FTP Username: username FTP Password: password FTP Port: 21 Upload File public string UploadFile(string FtpUrl, string fileName, string userName, string password, string…

Read More

ASP.NET Identity reset password

var Db = new ApplicationDbContext(); var userDetail = Db.Users.FirstOrDefault(u => u.UserName.Equals(Username)); String userId = userDetail.Id; String newPassword = “pa$$word”; ApplicationUser cUser = UserManager.FindById(userId); String hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword); UserStore store = new UserStore(); cUser.PasswordHash = hashedNewPassword; UserManager.UpdateAsync(cUser);…

Read More