Skip to content

Instantly share code, notes, and snippets.

@dev1ne
dev1ne / new_gist_file
Created August 2, 2013 19:59
jQuery email validation
function IsEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}
//m_c1_txtReqEmail
var TempEmail = $('#m_c1_txtReqEmail').val();
if (IsEmail(TempEmail) == false) {
$('#m_c1_txtReqEmail').addClass("error");
error += "\n - Invalid Email Address";
@dev1ne
dev1ne / new_gist_file
Created August 2, 2013 19:44
Make item scroll slower than window (Parallax)
$(window).scroll(function () {
$('#object').css({
'bottom' : -($(this).scrollTop()/10)+"px" // increase # to make even slower
});
});
@dev1ne
dev1ne / new_gist_file
Created August 2, 2013 19:43
jQuery polling
<div class="status">polling ...</div>
<script type="text/javascript">
$(document).ready(function() {
(function poll() {
setTimeout(function() {
$.ajax({
url: "/websites/1.json",
type: "GET",
success: function(data) {
@dev1ne
dev1ne / new_gist_file
Created August 2, 2013 19:39
Replace [AT] and [DOT] in mailto links in jQuery
/*********************************
MAIL LINKS
*********************************/
$('a[href^="mailto"]').each(function(){
var $link = $(this);
var href = $link.attr('href');
var text = $link.text();
href=href.replace('[AT]','@');
href=href.replace('[DOT]','.');
text=text.replace('[AT]','@');
@dev1ne
dev1ne / new_gist_file
Created August 2, 2013 19:36
Responsiveness with jQuery
$(window).resize(function() {
var width = $(window).width();
if (width < 960) {
// Do Something for example "$('body').addClass('960');"
}
else {
//Do Something Else
}
});
@dev1ne
dev1ne / new_gist_file
Created August 2, 2013 19:34
Limit characters in textarea (with maxlength attribute fallback)
//Limit max characters in textarea
$(".textarea-limit").each(function () {
var thistextarea = $(this);
var characters = thistextarea.prop('maxlength');
thistextarea.prev('label').append("<span class='limit-counter'>You have <strong>"+ characters+"</strong> characters remaining</span>");
var counter = thistextarea.prev('label').find('.limit-counter');
counter.css('float','right');
function displaycounter(countervar) {
var remaining = characters - countervar.val().length;
counter.html("You have <strong>"+ remaining+"</strong> characters remaining");