Posts Tagged ‘validation’

Modal Popup Extender, AJAX Tool Kit, Validation Controls ASP.NET

Tuesday, September 2nd, 2008

I am using Modal popup Extender in my project which after click save button appears and takes Reason for doing that action as an input. I am using a text box labelling Reason for change; if that box is empty I am telling my transaction to roll back. So to make changes appear in database user has to fill the reason. I wanted to validate that using required validation control of Asp.net but it was firing the validation on parent page so it was not showing me modal popup. Then I used JavaScript to validate that box and it worked. I am using JavaScript behind my modal popup panel OK button which checks if reason to change is empty then show warning and do not proceed until unless user provides the reason for change.

<script type=”text/javascript”>

function ValidateReason()

{

if(document.getElementById(‘<%=txtChangeReason.ClientID%>’).value==“”)

{

alert(“Please enter reason for change!”);

window.event.returnValue = false;

return false;

}

return true;

}

</script>

window.event.returnValue = false; this line cancels all event without this line modal popup was hiding itself without validation. Please leave your comments or anyother way around.

Reqular experssion RegEx, C# , asp.net , vb.net

Friday, April 25th, 2008

Regular expression:

Regular Expression is a great way to manipulate strings for example matching, finding, validating Data, Specailly string manipulaion becames handy while we use reqular expression.

We can use Regular expression on both Serer and client side. We do use it with asp.net validation controls.

Charcther matching:

. ^ $ * + ? { [ ] \ | ( )

\d Matches any decimal digit. This is equivalent to the class [0-9].

\D Matches any non-digit character. This is equivalent to the class

[^0-9].

\s Matches any whitespace character; this is equivalent to the class

[ \t\n\r\f\v].

\S Matches any non-whitespace character; this is equivalent to the class [^ \t\n\r\f\v].

\w Matches any alphanumeric character; this is equivalent to the class [a-zA-Z0-9_].

\W Matches any non-alphanumeric character; this is equivalent to the class [^a-zA-Z0-9_].

Period or dot “.” When used in Reqular expression could be any charcter other than new line characters.

[1234]Cricket will return 1,2,3 or 4 if they occur before Cricket OR

[1-4]Cricket

[a-m] ranges between a-m and A-M

“\” backslash and “?” Question Mark

(?) is used to find occurrence of previous character

(\) is use dto find exact occurance of pervious character

4{3}Cricket will return 444Cricket

“^” carrot ^cricket if cricket are first 7 charcters

“$” dollar $crikct if cricket are 7 last charcters

“\w+” is a word occurrence

(*) estrick means all

To check decimal or dot use \.?

?# is used to write commetns inside regular expression

To remove html Tags use “< (.+?)>”

If Input is a valid number or not:

To check if an input provided is a valid number use following reuglar expression

“(^([0-9]*|\d*\d{1}?\d*)$)”

Understating above expression will help how it works.