Trick to check your Regular expression


Thursday, March 10, 2011

Hello Friends,

Today i am going to explain you or provide you a trick by using which you can check your regular expression on page.

Let consider, we want to validate number input,
Like, you have "Mobile Number" field on your page, then it require only number input,

so here you will see, if you will enter Interger in text box, it will allow you to enter otherwise it will return error message.

So lets start here,

click on Start button at left botton of your destop screen, type notepad in run and open one notepad page.

Paste below code and select filetype as "all" and save as html page.

and then click on that page and open HTML page.

<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
     <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
         
     <script type="text/javascript">
            function rajesh(){
             alert(validate(document.getElementById("txtemailid").value));
             }
     
             function validate(text){
            return /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(text);
             }
        </script>

    </head>
    <body>
    <input type="text" id="txtemailid" name="txtemailid"/>
        <input type="button" value="check" onclick="return rajesh();"/>
    </body>
</html>




so you will see one text box, in which if you enter some text, it will return false, which means you cannot enter text in that field,



so now if you will enter number in that textbox then you will see it will return true, which means you can enter number in that field.




Explaination of code.
Step 1. Add this two files in head part of your page.

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>

Step 2. Add this script in head part of your page.

    <script type="text/javascript">
            function rajesh(){
             alert(validate(document.getElementById("txtemailid").value));
             }
     
             function validate(text){
            return /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(text);
             }
        </script>

in function rajesh(), you can see, i am calling another function named validate().

In validate function, you can see, i have kept your regular expression and passing value with name "text".

which will validate value "text" with regular expression and return true or false to you.

Step 3. In body part you can add UI part, which will have one textbox and submit button.

I am done now, so you can check this out at your end or if you have any issue or problem, please comment me, i will send you reply as soon possible.

or you can use this link to check our live code, http://jsfiddle.net/DhBrV/ or you can visit http://www.induway.com. to know more...


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer

Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com

getYear Date function of javascript gives alert as 111


Monday, February 7, 2011

Hello friends,

You might have encountered this issue many times while using datetimepicker on your modules.

For example, Datetimepicker is provideing you some other format of date and you want to display in some other format

or you want to add date, month or year to original date.

For example, if you are making alert of current date like below code then for date and month, you will get correct data
but for year you will wrong data.

so this you will be doing like this

var today =new Date();
alert(today);
alert(today.getMonth());
alert(today.getYear());

For today alert you will get
Mon Feb 07 2011 11:52:21 GMT+0530 (India Standard Time)

For today.getMonth() alert, you will get,
02

For today.getYear() alert you will get,
111

which is wrong, that should alert 2011,

This is because getYear method returns the year minus 1900,


Solution to this,

Instead of getYear, Please use getFullYear javascript function,
this is give you current year as 2011

This issue mostly has been seen in Mozila browser.


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer

Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com


Validate Datetime with current Datetime using jQuery


Thursday, January 27, 2011

Suppose you want to validate both Date i.e with time and without time with current date and time,
that is, selected data should be greater that current date.

with time
27/01/2011 13:01

without time
27/01/2011

Below is the fuction, you can make use of it and you can check that selected date and time is greater or lesser than current date and time.

This function will return true and false,

if selected date is less than current date and time, then it will return false, else it will return true.




function CompareToForToday(value,params)
            {
               if(value!='')
        {
                    var mdy = value.split('/')     //Date and month split
                    var mdyhr= mdy[2].split(' ');  //Year and time split
                   
                    
                    if(mdyhr[1] == undefined){
                        var valuedate= new Date(mdyhr[0], mdy[1]-1, mdy[0]);
                    }
            else
                    {
                        var mdyhrtime=mdyhr[1].split(':');
                        var valuedate= new Date(mdyhr[0], mdy[1]-1, mdy[0], mdyhrtime[0], mdyhrtime[1]);
                    }

                    var d = new Date();
                    if(mdyhr[1] == undefined){
                        var todaydate = new Date(d.getFullYear(), d.getMonth(), d.getDate());
                    }
                    else
                    {
                        var mdyhrtime=mdyhr[1].split(':');
                        var todaydate = new Date(d.getFullYear(), d.getMonth(), d.getDate(),d.getHours(),d.getMinutes());
                    }

                    return Date.parse(valuedate) > Date.parse(todaydate);
                }
                else
                {
                    return true;
                }
            }



Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com

How to create Trigger in SQL server ?


Thursday, December 16, 2010

In this post you can see, how to create trigger in SQL server 2005/2008


ALTER TRIGGER t_XYZ_Update 
   ON  tbl_tableName1
   AFTER UPDATE
AS 
IF ( UPDATE (tableField1) OR UPDATE (tableField2) OR UPDATE (tableField3) OR UPDATE (tableField4))
    BEGIN
    SET NOCOUNT ON;
    
    DELETE FROM tbl_tableName2 WHERE FieldId=(select FieldId from inserted)
    print 'Row Deleted Successfully'
    END
GO



Name you trigger like below line

ALTER TRIGGER t_XYZ_Update


Assign the table name on which you have to perform operation like below line


ON  tbl_tableName1


Design when you want to allow this trigger to get fire, here let take after UPDATE operation.


AFTER UPDATE


If any of the tbl_tableName1 field like tableField1,tableField2,tableField3,tableField4 get updated outside by query or in SP, then this trigger will get fire and perform operation assign to this trigger, you can find when field get updated by below query,

 
IF ( UPDATE (tableField1) OR UPDATE (tableField2) OR UPDATE (tableField3) OR UPDATE (tableField4))



Here in below box, you can see the operation you want to perform when this trigger get fire, here we have used "inserted" table, whenever any of field found updated, same row is inserted in "inserted" table so by this table you can find which row is updated and you can make use of that rowid to perform other operation,

 
    BEGIN
    SET NOCOUNT ON;
    
    DELETE FROM tbl_tableName2 WHERE FieldId=(select FieldId from inserted)
    print 'Row Deleted Successfully'
    END



Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer

Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com

Prevent table from drop and re-create during saving changes


Thursday, December 2, 2010

Hello Friends,

Problem : Whenever you make any changes in the table defination, when table is fill with data or rows,it does not allow you to delete or make any changes to table.


Solution : You might have faced this issue many times, when ever you make any changes in the table defination and you try to save changes, then you might have seen error messages as shown in below image.




So here is the steps by which you can avoid dropping of table or re-creating it again by using below steps..

Step 1. There is one option in sql server, which allow you to save your changes to table without droping it.

You just click on Tool option in top menu, See below images you can see from where you can go to tool option,




Step 2. Then click on "Option",
then you will be prompt with options Box, in that you will see left menu, in that explore "Designers" option.


After Exploring Designers option, just click on "table and database designer", you will see below screen

Step 3. In below snap, you can see the field in Red Box, just untick it, so that you can save change.



Untick - Prevent saving changes that require table re-creation


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com