Customizing SMF > SMF Coding Discussion

Profile Field Input Mask (Regex)

(1/6) > >>

Jade Elizabeth:
I need to put an input mask on my profile field....but I don't know how they work or how to write it. It's probably simple but it's over my head.


I want the field to REJECT anything that says a word, and a phrase.....for the purpose of this if it says "facebook" or "face book" I want it to completely reject the input, or even better - change it to say "no one".

Can anyone help me with this please? :D

The Craw:
Easy stuff. Gimme a moment to write something that works. ;)

Jade Elizabeth:
THANK YOU THANK YOU THANK YOU! :D

The Craw:
Okay, here ya go. Just slide this into the html head or body and it will test the input as they user types. Should they enter either "facebook" or "face book" it will change the input value with whatever you put in the replace_value variable. You'll also have to change the input_id to whatever the id of your input is. :P


--- Code: ---<script type="text/javascript">
var input_id = 'mask_input';
var replace_value = 'Nobody';

var input = null;

bind_event(window, 'load', function()
{
input = document.getElementById(input_id);

bind_event(input, 'keyup', function()
{
if (input.value.match(/face( )?book/i))
input.value = replace_value;
});
});

function bind_event(element, event, callback)
{
if (element.addEventListener)
element.addEventListener(event, callback, false);

else if (element.attachEvent)
element.attachEvent('on' + event, callback);
}
</script>

--- End code ---

Edit: I've attached the full test file for an example if it helps.

Jade Elizabeth:
Ha ha this is embarrassing...if you create a custom profile field there's an input mask option...do I put that in there or another thing? That looks like I can make it yell at people for putting in the phrase I don't like....which I like the idea of >:D.

It's under advanced settings...

Admin > Features and Options > Profile Fields

I made a text field that's required on registering, it's called "invited by" ha ha. I'm off to bed so I will reply in the morning <3 :D.

Navigation

[0] Message Index

[#] Next page

Go to full version