Script to Remove or Check Special Charater from Javascript

To Remove or Check Special Charater from Javascript

Call  Javascript function on “onkeyup” event of TextBox

<asp:TextBox ID=”TextBox1″ runat=”server” onkeyup=”valid(this)” Width=”610px”></asp:TextBox>

Javascript :

<script type=”text/javascript”>

function valid(field) {
var txt = document.getElementById(‘TextBox1′).value;
var iChars = “!@$%^&*()+=-[]\\\’;,./{}|\”:<>?~_”;
for (var i = 0; i < txt.length; i++) {
if (iChars.indexOf(txt.charAt(i)) != -1) {
alert(“Your string has special characters. \nThese are not allowed.”);
document.getElementById(‘TextBox1’).value = txt.substring(0, txt.length – 1);
return false;


Above script check all given Special character which is in iChars and substring function will remove that entered character

Sharepoint 2010 How to read File from Library

To read File from Library and replace that value in Sharepoint library use below code.

protected void btnReadFile_Click(object sender, EventArgs e)
string strSubject = “New Subject Line”;
string strMessage = “New Message Line”;

string content = string.Empty;
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
using (SPWeb oWeb = oSite.OpenWeb())
SPDocumentLibrary doclib = (SPDocumentLibrary)oWeb.GetList(“Documents”);
SPFile htmlFile = doclib.Items[0].File;
using (System.IO.StreamReader reader = new System.IO.StreamReader(htmlFile.OpenBinaryStream()))
content = reader.ReadToEnd();

content = content.Replace(“@xSubjectx@”, strSubject);
content = content.Replace(“@xMessagex@”, strMessage);
lblOutput.Text = content;


How to pass URL in Link and open Outlook

To Open outlook from Link and also send Url use following code

<script language=”javascript” type=”text/javascript”>
var varname = “;;

Now get that variable value in Link as

<a href=” can specify subject too&body=”onclick=”location.href=this.href+”+varname;return false;”>Send Email</a>