I don't know why your code does not work when there is #
in your input value in caml query.
But Refer below code that works perfectly for me.
function retrieveListItems() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('TestList');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Contains><FieldRef Name="Title" /><Value Type="Text">#rohit</Value></Contains></Where></Query></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
alert(oListItem.get_item('Title'));
}
alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
debugger;
}