user2719152
user2719152

Reputation: 989

Hide characters in HTML?

I am writing an application in Django and i have to show some information and hide some like if contact number is "9087654321" then i want to show this like "908*****21". I don't know java script. So how can i do it only with HTML and CSS.I am a newbie so please be generous and easy. Thanking you in anticipation.

Upvotes: 4

Views: 1058

Answers (3)

erikvimz
erikvimz

Reputation: 5476

You can try this:

var contactNumber = "9087654321";
var maskedNumber = contactNumber.substr(0, 3) + Array(contactNumber.length - 4).join('*') + contactNumber.substr(contactNumber.length - 2, 2);

Takes the first 3 and last 2 numbers and fills the gap with stars(asterisk).

Result of maskedNumber would be 908*****21

For security reasons I would recommend PatNowak's answer as it hides the contact number before it is sent to the client.

Upvotes: 1

PatNowak
PatNowak

Reputation: 5812

The are two ways to deal with that- first one is one, which was presented by Erik Kralj- use Javascript.

Second one is use Python to do so. You can write a method in your view, which will hide this sensitive data for user, which is not logged in etc.

Then just use in Python:

no = list(no)
no[3:-2] = "*" * len(no[3:-2])

Upvotes: 1

PDKnight
PDKnight

Reputation: 722

This should work:

var str = "9087654321";
str.slice(0,3) + str.slice(3,-2).replace(/./g,'*') + str.slice(-2);
// "908*****21"

Works with every contact number.

Upvotes: 2

Related Questions